Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support customHeader for client #2064

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/vulncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ 1.23.5 ]
go-version: [ 1.23.6 ]
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
Expand Down
11 changes: 11 additions & 0 deletions 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 @@ -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
Loading