http4s / http4s

A minimal, idiomatic Scala interface for HTTP

Home Page:https://http4s.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for comma separated headers

ghostbuster91 opened this issue · comments

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

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.