Skip to content

Commit

Permalink
support customHeader
Browse files Browse the repository at this point in the history
support customHeader
  • Loading branch information
jiuker committed Feb 10, 2025
1 parent 3eb28ad commit 8706190
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ type Client struct {

trailingHeaderSupport bool
maxRetries int

// Custom headers to be added to all requests.
customHeader http.Header
}

// Options for New method
Expand Down Expand Up @@ -150,6 +153,8 @@ type Options struct {
// Number of times a request is retried. Defaults to 10 retries if this option is not configured.
// Set to 1 to disable retries.
MaxRetries int

CustomHeader http.Header
}

// Global constants.
Expand Down Expand Up @@ -193,7 +198,7 @@ func New(endpoint string, opts *Options) (*Client, error) {
// for backwards compatibility.
clnt.s3DualstackEnabled = true
}

Check failure on line 201 in api.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.22.x and ubuntu-latest

File is not properly formatted (goimports)

Check failure on line 201 in api.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.23.x and ubuntu-latest

File is not properly formatted (goimports)
return clnt, nil
}

Expand Down Expand Up @@ -311,6 +316,9 @@ func privateNew(endpoint string, opts *Options) (*Client, error) {
clnt.maxRetries = opts.MaxRetries
}

// Set custom headers
clnt.customHeader = opts.CustomHeader

// Return.
return clnt, nil
}
Expand Down Expand Up @@ -881,6 +889,9 @@ func (c *Client) newRequest(ctx context.Context, method string, metadata request
c.setUserAgent(req)

// Set all headers.
for k, v := range c.customHeader {
req.Header.Set(k, v[0])
}
for k, v := range metadata.customHeader {
req.Header.Set(k, v[0])
}
Expand Down

0 comments on commit 8706190

Please sign in to comment.