Does the order of headers in an HTTP response ever matter?

后端 未结 5 574
时光说笑
时光说笑 2020-12-01 05:47

Is it ever meaningful whether the order of headers is

A: 1
B: 2

vs

B:2
A:1

I\'m trying to figure out if I

5条回答
  •  时光取名叫无心
    2020-12-01 06:39

    RFC 7230, section 3.2.2: Field Order addresses this question specifically. Quotes here are from that section of the specification, with emphasis added by me:

    The order in which header fields with differing field names are received is not significant.

    It goes on to qualify that with a note about good practice for the sake of performance:

    However, it is good practice to send header fields that contain control data first, such as Host on requests and Date on responses, so that implementations can decide when not to handle a message as early as possible.

    In certain cases it is permissible for a message to contain multiple header fields with the same name. In this case, order does matter.

    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.

提交回复
热议问题