views:

41

answers:

2

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)?

HTTP 1.1 Section 4.2:

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.

A: 

Since duplicate headers can cause issues with various web-servers and APIs (regardless of what the spec says), I doubt there is any general purpose use case where this is best practice. That's not to say someone somewhere isn't doing it, of course.

kekekela
Message format and APIs have different requirements...
Julian Reschke
thanks for that, guessing english isn't your first language but various != all
kekekela
+1  A: 

It's only allowed for headers using a very specific format, see RFC 2616, Section 4.2.

Julian Reschke
He stated pretty clearly in the question that he realizes its allowed, that's not what he's asking.
kekekela