Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for comma separated headers #7431

Open
ghostbuster91 opened this issue Apr 17, 2024 · 1 comment
Open

Add support for comma separated headers #7431

ghostbuster91 opened this issue Apr 17, 2024 · 1 comment

Comments

@ghostbuster91
Copy link

ghostbuster91 commented Apr 17, 2024

Hi,

We noticed that there is a difference in how headers are parsed depending on how multiple headers are passed.

It is ok if they are passed separately:

$ curl localhost:8080 -H "X-Foo:123" -H "X-Foo: 456"

then on the scala side this is represented as Some(NonEmptyList(X-Foo: 123, X-Foo: 456))

but according to the RFC passing them as a comma separated list should be equivalent:

$ curl localhost:8080 -H "X-Foo:123, 456"

However above is represented as Some(NonEmptyList(X-Foo: 123, 456))

Since http4s does already a great job when it comes to parsing low-level http data in every other area we wonder whether it would make sense also to support this case. What do you think?

tested on: 0.23.25

@danicheg
Copy link
Member

danicheg commented Apr 17, 2024

but according to the RFC passing them as a comma separated list should be equivalent

Actually, I'm not sure that the server MUST interpret these values as having two values, "123" and "456", not as a single value "123, 456".

https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.2
A sender MUST NOT generate multiple header fields with the same field
name in a message unless either the entire field value for that
header field is defined as a comma-separated list [i.e., #(values)]
or the header field is a well-known exception (as noted below).
A recipient MAY combine multiple header fields with the same field
name into one "field-name: field-value" pair, without changing the
semantics of the message, by appending each subsequent field value to
the combined field value in order, separated by a comma. The order
in which header fields with the same field name are received is
therefore significant to the interpretation of the combined field
value; a proxy MUST NOT change the order of these field values when
forwarding a message.

Also, in the latest spec

https://www.rfc-editor.org/rfc/rfc9110.html
A recipient MAY combine multiple field lines within a field section that have the same field name into one field line, without changing the semantics of the message, by appending each subsequent field line value to the initial field line value in order, separated by a comma (",") and optional whitespace (OWS, defined in Section 5.6.3). For consistency, use comma SP.

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

No branches or pull requests

2 participants