From f4a9b7816daf3f3e3c04479cb1ae2668436146d0 Mon Sep 17 00:00:00 2001 From: jiuker Date: Mon, 10 Feb 2025 12:04:44 +0800 Subject: [PATCH] support customheader support customheader --- .github/workflows/vulncheck.yml | 2 +- api.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/vulncheck.yml b/.github/workflows/vulncheck.yml index 217947ebd..01a88db3e 100644 --- a/.github/workflows/vulncheck.yml +++ b/.github/workflows/vulncheck.yml @@ -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 diff --git a/api.go b/api.go index 1b4842ad1..2396c2e66 100644 --- a/api.go +++ b/api.go @@ -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 @@ -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. @@ -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 } @@ -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]) }