请求指定无效 Content-Encoding 标头的适当 HTTP 状态代码? [英] Appropriate HTTP status code for request specifying invalid Content-Encoding header?

查看:23
本文介绍了请求指定无效 Content-Encoding 标头的适当 HTTP 状态代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果客户端发送 HTTP 请求并指定了服务端无法解码的 Content-Encoding 标头,应该返回什么状态码?

What status code should be returned if a client sends an HTTP request and specifies a Content-Encoding header which cannot be decoded by the server?

示例

客户端将 JSON 数据发布到 REST 资源并使用 gzip 编码对实体主体进行编码.但是,服务器只能解码 DEFLATE 编码,因为它未能通过服务器学校的 gzip 类.

A client POSTs JSON data to a REST resource and encodes the entity body using the gzip coding. However, the server can only decode DEFLATE codings because it failed the gzip class in server school.

应该返回什么 HTTP 响应代码?我会说 415 Unsupported Media Type,但问题不是实体的 Content-Type —— 而是其他受支持的实体主体的编码.

What HTTP response code should be returned? I would say 415 Unsupported Media Type but it's not the entity's Content-Type that is the problem -- it's the encoding of the otherwise supported entity body.

哪个更合适:415?400?也许是自定义响应代码?

Which is more appropriate: 415? 400? Perhaps a custom response code?

附录:当然,我已经彻底检查了 rfc2616.如果答案在那里,我可能需要一些新的矫正眼镜,但我不相信它是.

Addendum: I have, of course, thoroughly checked rfc2616. If the answer is there I may need some new corrective eyewear, but I don't believe that it is.

更新:

这与发送客户端可能无法接受的响应无关.问题是客户端正在向服务器发送可能是或可能不是服务器无法理解的编码中的有效媒体类型(根据客户端与请求消息一起打包的 Content-Encoding 标头).

This has nothing to do with sending a response that might be unacceptable to a client. The problem is that the client is sending the server what may or may not be a valid media type in an encoding the server cannot understand (as per the Content-Encoding header the client packaged with the request message).

这是一种边缘情况,在处理浏览器用户代理时不会遇到,但它可能会出现在接受实体主体以创建/修改资源的 REST API 中.

It's an edge-case and wouldn't be encountered when dealing with browser user-agents, but it could crop up in REST APIs accepting entity bodies to create/modify resources.

推荐答案

在我阅读时,415 Unsupported Media Type 听起来是最合适的.

As i'm reading it, 415 Unsupported Media Type sounds like the most appropriate.

来自 RFC 2616:

From RFC 2616:

服务器拒绝为请求提供服务,因为请求实体的格式不受所请求方法的请求资源支持.

10.4.16 415 Unsupported Media Type

The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method.

是的,文本部分说媒体类型";而不是编码",但实际描述中并未提及该区别.

Yeah, the text part says "media type" rather than "encoding", but the actual description doesn't include any mention of that distinction.

新的热点 RFC 7231 是偶数明确说明:

The new hotness, RFC 7231, is even explicit about it:

415(不支持的媒体类型)状态码表示
源服务器拒绝为请求提供服务,因为有效负载
在目标资源上采用此方法不支持的格式.
格式问题可能是由于请求的指示
Content-Type 或 Content-Encoding
,或作为检查的结果
直接数据.

6.5.13. 415 Unsupported Media Type

The 415 (Unsupported Media Type) status code indicates that the
origin server is refusing to service the request because the payload
is in a format not supported by this method on the target resource.
The format problem might be due to the request's indicated
Content-Type or Content-Encoding
, or as a result of inspecting the
data directly.

这篇关于请求指定无效 Content-Encoding 标头的适当 HTTP 状态代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆