This is an automated email from the ASF dual-hosted git repository.

zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-go.git


The following commit(s) were added to refs/heads/main by this push:
     new 4390ffec fix(catalog): handle content-type header correctly for 
fetchToken (#673)
4390ffec is described below

commit 4390ffec5afbad9fcd7f2c9accdd55a41bb6f6e4
Author: ferhat elmas <[email protected]>
AuthorDate: Fri Jan 9 21:25:01 2026 +0100

    fix(catalog): handle content-type header correctly for fetchToken (#673)
    
    related to #652
    
    Signed-off-by: ferhat elmas <[email protected]>
---
 catalog/rest/rest.go      |  5 +++++
 catalog/rest/rest_test.go | 22 ++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/catalog/rest/rest.go b/catalog/rest/rest.go
index 8c48d675..fc6712be 100644
--- a/catalog/rest/rest.go
+++ b/catalog/rest/rest.go
@@ -209,6 +209,11 @@ const emptyStringHash = 
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991
 
 func (s *sessionTransport) RoundTrip(r *http.Request) (*http.Response, error) {
        for k, v := range s.defaultHeaders {
+               // Skip Content-Type if it's already set in the request
+               // to avoid duplicate headers (e.g., when using PostForm)
+               if http.CanonicalHeaderKey(k) == "Content-Type" && 
r.Header.Get("Content-Type") != "" {
+                       continue
+               }
                for _, hdr := range v {
                        r.Header.Add(k, hdr)
                }
diff --git a/catalog/rest/rest_test.go b/catalog/rest/rest_test.go
index 8135a864..445ea4b4 100644
--- a/catalog/rest/rest_test.go
+++ b/catalog/rest/rest_test.go
@@ -235,6 +235,28 @@ func (r *RestCatalogSuite) TestToken401() {
        r.ErrorContains(err, "invalid_client: credentials for key invalid_key 
do not match")
 }
 
+func (r *RestCatalogSuite) TestTokenContentTypeDuplicated() {
+       r.mux.HandleFunc("/v1/oauth/tokens", func(w http.ResponseWriter, req 
*http.Request) {
+               r.Equal(http.MethodPost, req.Method)
+
+               values := req.Header.Values("Content-Type")
+               r.Equal([]string{"application/x-www-form-urlencoded"}, values)
+
+               w.WriteHeader(http.StatusOK)
+
+               json.NewEncoder(w).Encode(map[string]any{
+                       "access_token":      TestToken,
+                       "token_type":        "Bearer",
+                       "expires_in":        86400,
+                       "issued_token_type": 
"urn:ietf:params:oauth:token-type:access_token",
+               })
+       })
+
+       cat, err := rest.NewCatalog(context.Background(), "rest", r.srv.URL, 
rest.WithCredential(TestCreds))
+       r.Require().NoError(err)
+       r.NotNil(cat)
+}
+
 func (r *RestCatalogSuite) TestWithHeaders() {
        namespace := "examples"
        customHeaders := map[string]string{

Reply via email to