Does the HTTP Protocol support multiple content types in response headers?

后端 未结 2 1897
执笔经年
执笔经年 2020-12-01 17:57

I\'m wondering if I can return the response header

Content-Type: application/json text/json 

or isn\'t this legal?

The HTTP protoc

相关标签:
2条回答
  • 2020-12-01 18:28

    You need to look at the definition of the header field:

    http://greenbytes.de/tech/webdav/rfc2616.html#rfc.section.14.17

    Content-Type = "Content-Type" ":" media-type

    so it takes a single media-type, which is defined by the grammar you quoted above.

    So the answer is: a single type/subtype, followed by optional parameters.

    0 讨论(0)
  • 2020-12-01 18:45

    No. As pointed out in the accepted answer, the header value itself does not allow for multiple values, and it is also not allowed to send multiple Content-Type headers:

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

    https://tools.ietf.org/html/rfc7230#section-3.2.2

    None of the "escape clauses" holds, because media-type does not allow a comma-separated list of values, and Content-Type evidently is not a well-known exception, either.

    0 讨论(0)
提交回复
热议问题