As far as I know it is allowed by the HTTP spec to set more than one HTTP header with the same name. Is there any use case to do so (from client to server and vice versa)?
Multiple message-header fields with
the same field-name MAY be present in
a message if and only if the entire
field-value for that header field is
defined as a comma-separated list
[i.e., #(values)]. It MUST be possible
to combine the multiple header fields
into one “field-name: field-value”
pair, without changing the semantics
of the message, by appending each
subsequent field-value to the first,
each 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, and thus a
proxy MUST NOT change the order of
these field values when a message is
forwarded.
If I’m not wrong there is no case where multiple headers with the same name are needed.
It’s commonly used for
Set-Cookie:. Many servers set more than one cookie.Of course, you can always set them all in a single header.Actually, I think you cannot set multiple cookies in one header. So that’s a necessary use-case.The Cookie spec (RFC 2109) does claim that you can combine multiple cookies in one header the same way other headers can be combined (comma-separated), but it also points out that non-conforming syntaxes (like the
Expiresparameter, which has,s in its value) are still common and must be dealt with by implementations.So, if you use
Expiresparams in yourSet-Cookieheaders and you don’t want all your cookies to expire at the same time, you probably need to use multiple headers.Update: Evolution of the Cookie spec
RFC 2109 has been obsoleted by RFC 2965 that in turn got obsoleted by RFC 6265, which is stricter on the issue:
Side note
RFC 6265 uses the verb "folding" when it refers to combining multiple header fields into one, which is ambiguous in the context of the HTTP/1 specs (both by RFC2616, and its successor, RFC 7230) where:
"folding" consistently refers to line folding, and
the verb "combine" is used to describe merging same headers.
Combining header fields:
See RFC 2616, Section 4.2, Message Headers (quoted in the question), but searching for the for the word "combine" will bring up special cases.
The above item obsoleted by RFC 7230, Section 3.2.2, Field Order:
Line folding:
From RFC 2616, Section 2.2, Basic Rules:
The above section obsoleted by RFC 7230, Section 3.2.4, Field Parsing: