是否有一个可接受的HTTP头的最大允许大小?如果有,是什么?如果不是,这是特定于服务器的东西,还是允许任何大小的头的公认标准?
当前回答
我还发现在某些情况下,在许多头文件的情况下出现502/400的原因可能是因为有大量的头文件而不考虑大小。 来自文档
tune.http.maxhdr Sets the maximum number of headers in a request. When a request comes with a number of headers greater than this value (including the first line), it is rejected with a "400 Bad Request" status code. Similarly, too large responses are blocked with "502 Bad Gateway". The default value is 101, which is enough for all usages, considering that the widely deployed Apache server uses the same limit. It can be useful to push this limit further to temporarily allow a buggy application to work by the time it gets fixed. Keep in mind that each new header consumes 32bits of memory for each session, so don't push this limit too high.
https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#3.2-tune.http.maxhdr
其他回答
不,HTTP没有定义任何限制。然而,大多数web服务器确实限制了它们接受的头文件的大小。例如,在Apache的默认限制是8KB,在IIS是16K。如果报头大小超过限制,服务器将返回413实体过大错误。
相关问题:用户代理字符串可以有多大?
我还发现在某些情况下,在许多头文件的情况下出现502/400的原因可能是因为有大量的头文件而不考虑大小。 来自文档
tune.http.maxhdr Sets the maximum number of headers in a request. When a request comes with a number of headers greater than this value (including the first line), it is rejected with a "400 Bad Request" status code. Similarly, too large responses are blocked with "502 Bad Gateway". The default value is 101, which is enough for all usages, considering that the widely deployed Apache server uses the same limit. It can be useful to push this limit further to temporarily allow a buggy application to work by the time it gets fixed. Keep in mind that each new header consumes 32bits of memory for each session, so don't push this limit too high.
https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#3.2-tune.http.maxhdr
这是最流行的网络服务器的限制
Apache - 8K Nginx - 4K-8K Iis - 8k-16k 雄猫- 8K - 48K 节点(<13)- 8K;(>13) - 16k
2011年的RFC 6265规定了cookie的具体限制。
https://www.rfc-editor.org/rfc/rfc6265 6.1. 限制
实际的用户代理实现在数量和 它们可以存储的cookie大小。一般使用的用户代理应该 提供以下每个最低功能:
o每个cookie至少4096个字节(由 cookie的名称、值和属性的长度)。
o每个域至少50个cookie。
o总共至少3000个饼干。
服务器应该使用尽可能少和尽可能小的cookie来避免 达到这些实现限制并使网络最小化 由于Cookie报头包含在每个请求中的带宽。
如果用户代理返回失败,服务器应该正常降级 Cookie头中的一个或多个Cookie,因为用户代理可能会 在任何时间从用户的命令驱逐任何cookie。
--
RFC的预期受众是用户代理或服务器必须支持的内容。似乎要调优您的服务器以支持浏览器所允许的功能,您需要配置4096*50作为限制。正如下面的文本所示,这似乎远远超出了典型web应用程序所需要的。使用当前限制和RFC概述的上限,并比较较高配置的内存和IO结果是很有用的。
如果您打算使用任何像Akamai这样的DDOS提供商,他们的响应头大小最大限制为8k。所以尽量将响应头大小限制在8k以下。
推荐文章
- 什么是HTTP“主机”报头?
- 哪个HTTP状态代码表示“尚未准备好,稍后再试”?
- 如何阻止恶意代码欺骗“Origin”报头来利用CORS?
- 自定义HttpClient请求头
- 为什么说“HTTP是无状态协议”?
- 过期和缓存控制头之间的区别是什么?
- 我需要HTTP GET请求的内容类型报头吗?
- 如何让Chrome允许混合内容?
- 正确的方式删除cookies服务器端
- REST DELETE真的是幂等的吗?
- 了解Chrome网络日志“停滞”状态
- 用户代理字符串可以有多大?
- 什么是接受* HTTP报头q=0.5 ?
- HTTP状态码200(缓存)和状态码304之间有什么区别?
- HTTP POST返回错误:417“期望失败。”