중복된 HTTP 헤더는 모든 경우에 가능한가?
references
rfc-2616
4.2 Message Headers 에 다음과 같이 씨부라려져 있다.
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.
잘못된 해석을 한 번 하자면 다음과 같다.
그냥 됨.
간단하게 쓰면 될 일을 왜 저렇게 썼는지 곰곰히 살펴보도록 하자.
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)].
if and only if
와 그 뒤의 내용이 좀 껄쩍지근한 건 단지 느낌일 뿐인걸까?
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.
이 부분이 좀 중요한 것 같다. 역설적으로, 만약 다음과 같은 사용될 수 있다면,
My-Awesome-Header: value1 My-Awesome-Header: value2 My-Awesome-Header: value3
다음과 같이 콤마(‘,’)로 분리해서 한꺼번에 사용해도 동일한 의미와 순서를 가지는 헤더에 한해서, 위에 있는 것 처럼, 같은 이름으로 나눠서 사용할 수(MAY) 있다는 얘기다.
My-Awesome-Header: value1,value2,value3
Accept 헤더를 다음과 같이 사용하면
Accept: application/xml Accept: application/json
원래는 아래와 같이 사용해야 하는데 (그렇게 정의되어 있다.) 위처럼 사용할 수 있다는 의미다.
Accept: application/xml,application/json
하지만 Content-Type 를 다음과 같이 사용하면 안될 듯 하다.
PUT /items/1 HTTP/1.1 Host: whatever Content-Type: application/xml Content-Type: application/json ㅋㅋㅋ
다음과 같은 응답메시지를 볼 수 있을지도…
HTTP/1.1 400 씨발새꺄 장난하냐?