有实际的 HTTP 标头长度限制吗?

发布于 2024-07-26 15:41:07 字数 764 浏览 6 评论 0 原文

我有一个 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

懒的傷心 2024-08-02 15:41:07

尽管每个 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:

  • Apache 1.3, 2.0, 2.2, 2.3: 8190 Bytes (for each header field)
  • IIS:
    • 4.0: 2097152 Bytes (for the request line plus header fields)
    • 5.0: 131072 Bytes, 16384 Bytes with Windows 2000 Service Pack 4 (for the request line plus header fields)
    • 6.0: 16384 Bytes (for each header fields)
  • Tomcat:
    • 5.5.x/6.0.x: 49152 Bytes (for the request line plus header fields)
    • 7.0.x: 8190 Bytes (for the request line plus header fields)

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).

没企图 2024-08-02 15:41:07

是的,但限制是可配置的并且取决于平台。 例如,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).

生来就爱笑 2024-08-02 15:41:07

对于 Apache,我找到了Apache 安全性的服务器限制< /a> 文章列出了这些指令:

  # allow up to 100 headers in a request
  LimitRequestFields 100
  # each header may be up to 8190 bytes long
  LimitRequestFieldsize 8190

对于 Nginx,HttpCoreModule 中的 large_client_header_buffers 指令控制这一点:

请求的最长标头行也不能超过大小
一个缓冲区,否则客户端会收到错误“错误请求”(400)。

默认情况下,一个缓冲区的大小等于一页的大小,
取决于平台,4K 或 8K

For Apache, I found this Server Limits for Apache Security article that lists these directives:

  # allow up to 100 headers in a request
  LimitRequestFields 100
  # each header may be up to 8190 bytes long
  LimitRequestFieldsize 8190

For Nginx, the large_client_header_buffers directive from HttpCoreModule controls this:

The longest header line of request also must be not more than the size
of one buffer, otherwise the client get the error "Bad request" (400).

By default the size of one buffer is equal to the size of page,
depending on platform this either 4K or 8K

永不分离 2024-08-02 15:41:07

虽然您可以配置服务器,但您不太可能真正通过防火墙、负载平衡器和代理进行全程配置。 保持较小的标头大小可以避免出现问题。

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.

书信已泛黄 2024-08-02 15:41:07

Flash Media Server 4.5 具有非常短的默认标头长度限制,这可能会导致服务器根本不响应,特别是在 cookie 负载适中的情况下。

请参阅: Flash Media Server 4.5 配置和管理:配置服务器
配置 Apache HTTP Server:指定最大 HTTP 标头行长度

在 Flash Media Server Adaptor.xml 文件中,MaxHeaderLineLength
element 决定服务器可以处理的 HTTP 标头的大小。
MaxHeaderLineLength 的默认值为 1024 字节。 一些浏览器
发送大于 1024 字节的标头。 在这种情况下,Apache 发送
返回空响应。 要解决此问题,请配置
MaxHeaderLineLength 到 8192。

注意:默认情况下,Apache HTTP 标头大小限制为 8 KB(8190 字节加回车符)。

将其放在这里以防标头大小限制在 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

In the Flash Media Server Adaptor.xml file, the MaxHeaderLineLength
element determines the size of the HTTP header the server can handle.
The default value for MaxHeaderLineLength is 1024 bytes. Some browsers
send a header larger than 1024 bytes. In this scenario, Apache sends
back an empty response. To fix this issue, configure
MaxHeaderLineLength to 8192.

Note: By default, the Apache HTTP header size limit is 8 KB (8190 bytes plus a carriage return).

Putting this here in case the header size limit on Flash Media Server bites someone else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文