"accept type not supported" 的响应代码

Response code for "accept type not supported"

对于带有我不支持的 Accept header 的请求,正确的响应代码是什么?

例如,如果收到带有 Accept header application/json 的请求,但我支持的唯一响应类型是 text/plaintext/html,那么响应代码应该 return?

根据 RFC 7231,这将是 HTTP 响应 406:

6.5.6. 406 Not Acceptable

The 406 (Not Acceptable) status code indicates that the target
resource does not have a current representation that would be
acceptable to the user agent, according to the proactive negotiation
header fields received in the request (Section 5.3), and the server
is unwilling to supply a default representation.

The server SHOULD generate a payload containing a list of available representation characteristics and corresponding resource identifiers from which the user or user agent can choose the one most
appropriate. A user agent MAY automatically select the most
appropriate choice from that list. However, this specification does
not define any standard for such automatic selection, as described in Section 6.4.1.

来源:https://www.rfc-editor.org/rfc/rfc7231#section-6.5.6