Search code examples
socketshttp-headerswebserver

difference between http header code 413 and 414


I'm working on a simple web server that I want to handle long Get values. If request is larger than 4096, and it is GET value I want to send header code to client that understand request is too large.

client sends a huge cookie in buffer that make it larger than my web server can get.

which header code should I send? 414 Request-URI Too Long or 413 Payload Too Large?


Solution

  • client sends a huge cookie in buffer that make it larger than my web server can get.

    The client should be sending back only the cookies that your web server has previously given the client. If your own cookies are too large for your web server to handle, you need to shorten them.

    which header code should I send? 414 Request-URI Too Long or 413 Payload Too Large?

    Neither. The request URI is not what is too long, so 414 is not appropriate. And a GET request does not have a body, only headers, so 413 is not appropriate, either.

    The response code you should use is 431 Request Header Fields Too Large, which is defined in 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.