431 Request Header Fields Too Large
HTTP response status code 431 Request Header Fields Too Large is returned by the server to indicate that the HTTP headers are too large. This may indicate the total size used by all HTTP headers or instead, only that certain HTTP headers are too big.
Usage
When the 431 Request Header Fields Too Large status code is received, the server is refusing to process the HTTP request because there is too much data specified by the HTTP headers.
Depending on the server, this may refer to the total length of HTTP headers combined or instead, specific ones. In either case, the client may have the option to remove one or more HTTP headers and try the HTTP request again. One possible solution for limiting the number of HTTP headers is to cut or reduce the Cookies that are being transmitted.
Note
Search engines like Google will not index a URL with 431 Request Header Fields Too Large response status, and consequently, URLs that have been indexed in the past but are now returning this HTTP status code will be removed from the search results.
Example
In the example, the client requests a resource and the server responds with the 431 Request Header Fields Too Large status code because the combination of two very large cookie values exceeds the maximum limit set by the server for HTTP headers.
Request
GET /tech-news HTTP/1.1
Host: www.example.re
Cookie: first_cookie=<very_long>; second_cookie=<long again!>
Response
HTTP/1.1 431 Request Header Fields Too Large
Content-Type: text/html
Content-Length: 183
<html>
<head>
<title>Request Headers Too Long</title>
</head>
<body>
<p>Your request headers are too long. Try retrying the request without cookies.</p>
</body>
</html>
Code references
.NET
HttpStatusCode.RequestHeaderFieldsTooLarge
Rust
http::StatusCode::REQUEST_HEADER_FIELDS_TOO_LARGE
Rails
:request_header_fields_too_large
Go
http.StatusRequestHeaderFieldsTooLarge
Symfony
Response::HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE
Python3.5+
http.HTTPStatus.REQUEST_HEADER_FIELDS_TOO_LARGE
Apache HttpComponents Core
org.apache.hc.core5.http.HttpStatus.SC_REQUEST_HEADER_FIELDS_TOO_LARGE
Angular
@angular/common/http/HttpStatusCode.RequestHeaderFieldsTooLarge
Takeaway
The 431 Request Header Fields Too Large status code is a client error that is sent by the server when the client sends an HTTP request with too much data in the HTTP headers. If the HTTP request can be reduced in size while still making sense, then the HTTP request can be resubmitted with the smaller sized HTTP headers.