Accept and Accept-Charset - Which is superior?

前端 未结 5 717
攒了一身酷
攒了一身酷 2020-12-08 04:16

In HTTP you can specify in a request that your client can accept specific content in responses using the accept header, with values such as application/xm

5条回答
  •  死守一世寂寞
    2020-12-08 04:51

    RFC 7231 section 5.3.2 (Accept) clearly states:

    Each media-range might be followed by zero or more applicable media type parameters (e.g., charset)

    So a charset parameter for each content-type is allowed. In theory a client could accept, for example, text/html only in UTF-8 and text/plain only in US-ASCII.

    But it would usually make more sense to state possible charsets in the Accept-Charset header as that applies to all types mentioned in the Accept header.

    If those headers’ charsets don’t overlap, the server could send status 406 Not Acceptable.

    However, I wouldn’t expect fancy cross-matching from a server for various reasons. It would make the server code more complicated (and therefore more error-prone) while in practice a client would rarely send such requests. Also nowadays I would expect everything server-side is using UTF-8 and sent as-is so there’s nothing to negotiate.

提交回复
热议问题