我有一个 Web 应用程序,它使用 XmlHttpRequest 对象://www.w3.org/TR/XMLHttpRequest/#setrequestheader" rel="noreferrer">setRequestHeader API。 我使用自定义标头名称(例如 X-Foo)和 JSON 结构化值。 它不是 URL QueryString 或 POST 正文的一部分,因为它是有关请求的元信息。
标头值是否有实际大小限制? 如果我的 JSON 被截断,它将变得无法解析。 我最关心的是 Apache 2、Tomcat 6 和 IIS 7 中的限制。我在 Google 上搜索了 http 标头长度限制,但许多结果似乎已经过时。 用户代理字符串可以有多大?<中有一些相关评论/a> 但没有我想要的那么具体。
编辑:
我刚刚遇到了这个类似的问题 - http 标头值的最大值?
I have a web application that adds contextual information to XmlHttpRequest objects using the setRequestHeader API. I am using a custom header name (e.g. X-Foo) and a JSON structured value. It isn't part of the URL QueryString or POST body because it is meta information about the request.
Is there a practical size limit to the header value? If my JSON gets truncated, it becomes unparseable. I am most concerned with limits in Apache 2, Tomcat 6 and IIS 7. I did a Google search for http header length limit, but many of the results seem dated. There are some relevant comments in How big can a user agent string get? but not as specific as I would like.
Edit:
I just ran across this similar question - Maximum on http header values?
发布评论
评论(5)
尽管每个 Web 服务器软件都有一些限制,但 是否有限制是有区别的HTTP 请求行 加上标头字段或每个标头字段。
以下是摘要:
因此得出结论:要被上述所有 Web 服务器接受,请求的请求行加上标头字段不应超过 8190 字节。 这也是每个标头字段的限制(实际上甚至更少)。
Although each web server software has some limitations, there is a difference whether there’s a limit for the HTTP request line plus header fields or for each header field.
Here’s a summary:
So to conclude: To be accepted by all web servers above, a request’s request line plus header fields should not exceed 8190 Bytes. This is also the limit for each header fields (effectively even less).
是的,但限制是可配置的并且取决于平台。 例如,Tomcat 的默认限制为 8K。 我相信 IIS 6(不确定 IIS 7)有 16K 的限制。 我在对几个网站使用集成 Windows 身份验证时遇到了这个问题。 事实证明,我的安全令牌在编码到标头中时太大。 幸运的是,这些都是可配置的。 IIS 的注册表设置可以在 http://support.microsoft.com/kb/820129 中找到。 我相信要更改的关键设置是 MaxFieldLength(每个标头大小)和 MaxRequestBytes(请求的总大小)。
Yes, but the limits are configurable and dependent on platform. For example, Tomcat has a default limit of 8K. I believe that IIS 6, not sure about IIS 7, has a limit of 16K. I ran into this when using integrated windows authentication for several web sites. Turns out my security token was too large when encoded into the header. Fortunately, these are configurable. Registry settings for IIS can be found at http://support.microsoft.com/kb/820129. I believe the key settings to change are MaxFieldLength (per header size) and MaxRequestBytes (total size of request).
对于 Apache,我找到了Apache 安全性的服务器限制< /a> 文章列出了这些指令:
对于 Nginx,HttpCoreModule 中的 large_client_header_buffers 指令控制这一点:
For Apache, I found this Server Limits for Apache Security article that lists these directives:
For Nginx, the large_client_header_buffers directive from HttpCoreModule controls this:
虽然您可以配置服务器,但您不太可能真正通过防火墙、负载平衡器和代理进行全程配置。 保持较小的标头大小可以避免出现问题。
While you can configure the server, it's unlikely that you really can configure the whole way through firewalls, load balancers and proxies. Keeping the header size small keeps problems away.
Flash Media Server 4.5 具有非常短的默认标头长度限制,这可能会导致服务器根本不响应,特别是在 cookie 负载适中的情况下。
请参阅: Flash Media Server 4.5 配置和管理:配置服务器
配置 Apache HTTP Server:指定最大 HTTP 标头行长度
将其放在这里以防标头大小限制在 Flash Media Server 上咬了别人。
The Flash Media Server 4.5 has a very short default header length limit which can cause the server to simply not respond, particularly in circumstances where there is a moderate cookie load.
See: Flash Media Server 4.5 Configuration and Administration: Configuring the server
Configuring Apache HTTP Server: Specify the maximum HTTP header line length
Putting this here in case the header size limit on Flash Media Server bites someone else.