Skip to content
Merged
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
5 changes: 5 additions & 0 deletions catalog/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") != "" {
Comment on lines +212 to +214
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we have also optionally set Content-Type in createSession? Similar to X-Iceberg-Access-Delegation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the same case because we want it in default headers unconditionally but not in fetch token which sets directly to a different value (application/x-www-form-urlencoded). Even if it's set there optionally, it wouldn't prevent duplication

continue
}
for _, hdr := range v {
r.Header.Add(k, hdr)
}
Expand Down
22 changes: 22 additions & 0 deletions catalog/rest/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Loading