Skip to content

fix(autopatch): keep every value of multi-value headers - #1166

Merged
robtme merged 2 commits into
danielgtaylor:mainfrom
APX403:autopatch-multi-value-headers
Nov 17, 2026
Merged

robtme merged 2 commits into
danielgtaylor:mainfrom
APX403:autopatch-multi-value-headers

Conversation

@APX403

@APX403 APX403 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

With the net/http based adapters, a generated PATCH only keeps the last value of each header the PUT handler sets. For example, a PUT that returns two cookies:

type ThingResponse struct {
	SetCookie []http.Cookie `header:"Set-Cookie"`
	Body      *Thing
}

PUT /things/t1 sends Set-Cookie: a=1 and Set-Cookie: b=2, but PATCH /things/t1 only sends Set-Cookie: b=2. With huma.DefaultConfig, a Link header set by the handler is lost the same way, because the describedBy link that huma appends to the PUT response comes after it.

The PATCH handler copies the headers of the internal PUT response with one SetHeader call per value (autopatch.go#L450-L454), so each value replaces the previous one. The copy for a failed GET does the same (#L321-L325). Both now go through a small helper that sets the first value of each header and appends the others.

This came up in the review of #1130.

The PATCH handler copied the headers of the internal PUT response, and
of a failed GET, with one SetHeader call per value, so only the last
value of each header survived. A PATCH whose PUT set two cookies only
sent the second one. Set the first value and append the others.
@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.08%. Comparing base (51b0840) to head (40afb99).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1166      +/-   ##
==========================================
+ Coverage   94.75%   95.08%   +0.33%     
==========================================
  Files          25       30       +5     
  Lines        5224     5885     +661     
==========================================
+ Hits         4950     5596     +646     
- Misses        269      284      +15     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@robtme

robtme commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Thanks for following this up :) Setting the first value and appending the rest is exactly what we want, since the internal requests go back through the same middleware.

@robtme
robtme merged commit 2951860 into danielgtaylor:main Nov 17, 2026
2 checks passed
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.

2 participants