http头部代码413和414之间的差异

时间:2016-05-08 06:45:19

标签: sockets http-headers webserver

我正在处理一个简单的Web服务器,我想要处理很长的Get值。 如果请求大于4096,并且它是GET值,我想将头代码发送给理解请求太大的客户端。

客户端在缓冲区中发送一个巨大的cookie,使其比我的Web服务器更大。

我应该发送哪个标题代码? 414 Request-URI太长或413 Payload太大?

1 个答案:

答案 0 :(得分:1)

  

客户端在缓冲区中发送一个巨大的cookie,使其比我的Web服务器更大。

客户端应仅回送您的Web服务器先前为客户端提供的cookie。如果您自己的cookie太大而Web服务器无法处理,则需要缩短它们。

  

我应该发送哪个标题代码? 414 Request-URI太长或413 Payload太大?

都不是。请求URI不是太长,所以414不合适。并且GET请求没有正文,只有标题,因此413也不合适。

您应使用的响应代码为431 Request Header Fields Too Large,其在RFC 6585 Additional HTTP Status Codes中定义:

5.  431 Request Header Fields Too Large

   The 431 status code indicates that the server is unwilling to process
   the request because its header fields are too large.  The request MAY
   be resubmitted after reducing the size of the request header fields.

   It can be used both when the set of request header fields in total is
   too large, and when a single header field is at fault.  In the latter
   case, the response representation SHOULD specify which header field
   was too large.

   For example:

   HTTP/1.1 431 Request Header Fields Too Large
   Content-Type: text/html

   <html>
      <head>
         <title>Request Header Fields Too Large
      </head>
      <body>
         <h1>Request Header Fields Too Large
         <p>The "Example" header was too large.

</body> </html> Responses with the 431 status code MUST NOT be stored by a cache.