Skip to content

fix(go): fix Go client to normalize request header keys using Header.Set - #24766

Open
Wuchieh wants to merge 3 commits into
OpenAPITools:masterfrom
Wuchieh:master
Open

fix(go): fix Go client to normalize request header keys using Header.Set#24766
Wuchieh wants to merge 3 commits into
OpenAPITools:masterfrom
Wuchieh:master

Conversation

@Wuchieh

@Wuchieh Wuchieh commented Aug 24, 2026

Copy link
Copy Markdown

Use http.Header.Set when writing headerParams to http.Header in the generated Go client.

Previously, generated code directly assigned values to the underlying http.Header map:

headers[h] = []string{v}

This bypasses the header name canonicalization provided by http.Header.Set and may result in inconsistent header casing or duplicate logical headers.

This change replaces direct map assignment with:

headers.Set(h, v)

Changes

  • Use http.Header.Set when writing headerParams to http.Header.
  • Ensure request header names are canonicalized consistently.
  • Avoid inconsistent casing or duplicate logical headers caused by direct map assignment.
  • Add/update regression tests to cover the expected header handling behavior.

Related Issue

Fixes #24765

PR checklist


Summary by cubic

Normalizes request header keys in generated Go clients by using http.Header.Set instead of direct map assignment; previously headers[h] = []string{v} wrote non-canonical names, now headers.Set(h, v) canonicalizes and de-duplicates.

  • If headerParams includes case-variant duplicates, only one canonical header is sent; which value wins depends on map iteration order.
  • Updated modules/openapi-generator/src/main/resources/go/client.mustache and regenerated Go sample clients to reflect the change.

Written for commit 8265451. Summary will update on new commits.

Review in cubic

- Use Set when writing headerParams to http.Header to automatically apply canonical key formatting.
- Avoid inconsistent casing or duplicate header issues caused by direct map assignment.
@Wuchieh

Wuchieh commented Aug 24, 2026

Copy link
Copy Markdown
Author

@lwj5 Please review it.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 1 file

Re-trigger cubic

@wing328

wing328 commented Aug 25, 2026

Copy link
Copy Markdown
Member

please follow step 3 to update the samples so that CI can verify the change

cc @antihax (2017/11) @grokify (2018/07) @kemokemo (2018/09) @jirikuncar (2021/01) @ph4r5h4d (2021/04) @lwj5 (2023/04)

@wing328

wing328 commented Aug 25, 2026

Copy link
Copy Markdown
Member

please review the build failures when you've time, e.g. https://github.com/OpenAPITools/openapi-generator/actions/runs/32814668511/job/97700780542?pr=24766

@Wuchieh

Wuchieh commented Aug 25, 2026

Copy link
Copy Markdown
Author

please review the build failures when you've time, e.g. https://github.com/OpenAPITools/openapi-generator/actions/runs/32814668511/job/97700780542?pr=24766

Okay, I'll take a look later to see what the issue is.

…templates

- Update the go.mod Go version format for multiple Go client/server templates (e.g., 1.23 → 1.23.0, 1.25 → 1.25.0).
- Add missing terraform-plugin-testing checksums to the Terraform templates' go.sum.
- Sync checksums for indirect dependencies such as testify, x/sys, and x/text.
- Add go.sum files for templates including echo-server, chi-server, and gin-api-server-interface-only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][GO] Generated client does not use http.Header.Set for request headers

2 participants