本文介绍了请求指定无效Content-Encoding标头的适当HTTP状态代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 如果客户端发送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:是的,文本部分说的是媒体类型而不是编码,但实际描述没有包括对这种区别的任何提及。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: 这篇关于请求指定无效Content-Encoding标头的适当HTTP状态代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-18 03:13
查看更多