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

查看:1225
本文介绍了请求指定无效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数据POST到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不支持的媒体类型,但实体的内容类型不是问题 - 它是否则支持的实体主体的编码。

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不支持的媒体类型听起来最合适。

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

来自RFC 2616:

From RFC 2616:


10.4.16 415不支持的媒体类型



服务器拒绝为请求提供服务,因为请求的实体采用所请求资源不支持的格式对于所请求的方法。

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:


6.5.13。 415不支持的媒体类型



415(不支持的媒体类型)状态代码表示

源服务器拒绝为请求提供服务,因为有效负载< br>
采用此方法在目标资源上不支持的格式。

格式问题可能是由于请求指示的原因

Content-Type或内容编码
,或直接检查

数据的结果。

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天全站免登陆