Skip to content

Conversation

@gdeest
Copy link
Contributor

@gdeest gdeest commented Dec 12, 2025

Current handling of duplicate headers in MultiVerb client implementation is inconsistent with the Verb behavior. The latter allows duplicate header names, which is illustrated by a test-case that sets two distinct Set-Cookie headers. The MultiVerb implementation extracts the first matching header upon parsing, and removes the other instances.

I believe the Verb behavior is the correct choice as it allows some valid use-cases that are otherwise forbidden (e.g. multiple Set-Cookie). It will also allow some invalid behaviors (such as multiple Host headers) but this is a small price to pay.

This PR:

  • Demonstrates this issue with a MultiVerb-specific test-case. The test introduced by the first commit initially fails.
  • Then fixes the extractHeaders function to exhibit the same behavior as the Verb implementation.

@gdeest
Copy link
Contributor Author

gdeest commented Dec 12, 2025

Note: this probably needs a CHANGELOG entry.

@tchoutri
Copy link
Contributor

@gdeest let me know when you want a review for this PR. :)

@gdeest
Copy link
Contributor Author

gdeest commented Dec 15, 2025

@tchoutri I think it is reviewable as it is ! :-)

Comment on lines +190 to +192
-- This implementation retrieves the *first* header with matching name.
-- It leaves other instances of the same header intact for subsequent extraction, which allows
-- multiple headers with the same name to be extracted (e.g. Set-Cookie).
Copy link
Contributor

Choose a reason for hiding this comment

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

This behaviour should probably be put in the public documentation. :)

Copy link
Contributor Author

@gdeest gdeest Dec 16, 2025

Choose a reason for hiding this comment

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

Where exactly would you see it ? As module-level Haddock documentation ?

Note that this matches Verb behavior (this was actually motivated by / discovered via #1860 ).

Add test case that directly exercises MultiVerb's extractHeaders function
with duplicate header names (Set-Cookie headers). Fails with current
implementation, shows discrepancy with Verb (which has a similar test case).

The test uses WithHeaders with two Set-Cookie headers and verifies both
cookies are properly extracted on the client side.
The previous implementation used Seq.partition to remove ALL
headers with the matching name at once.

This commit changes its behavior to accept duplicate header names
(makes dual `Set-Cookie` test pass).
@gdeest gdeest force-pushed the servant-headers-semantics branch from e5610be to 8cbae7d Compare December 16, 2025 09:32
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