I am trying to use NestJs to develop an API. I am getting Http Error Code 431, when the bearer token passed as HTTP header is too long (around 2400 characters). But it works when the bearer token is around 1200 characters. Is there any setting that we can do to increase the header size limit? I am using nodejs12
1 Answers
The HTTP 431 Request Header Fields Too Large
response status code indicates that the server refuses to process the request because the request’s HTTP headers are too long. The request may be resubmitted after reducing the size of the request headers.
431 can be used when the total size of request headers is too large, or when a single header field is too large. To help those running into this error, indicate which of the two is the problem in the response body — ideally, also include which headers are too large. This lets users attempt to fix the problem, such as by clearing their cookies.
Servers will often produce this status if:
- The Referer URL is too long
- There are too many Cookies sent in the request
The below solution is not specific to nest.js but to any node.js server.
On running node --help
, you'll see one of the flag will be:
...
--max-http-header-size=... set the maximum size of HTTP headers (default: 8KB)
...
This Node.js CLI flag can help:
--max-http-header-size=16384
It sets the HTTP Max Headers Size to 16KB.
You can set this flag to the value you want.
See this for reference.
The documentation states the maximum size on this flag, so take care of that.

- 2,779
- 5
- 28
- 39
-
Thank you Karthick. I am getting this error only in my local environment(I am using nvm). I am not seeing this error when I deploy it as AWS Lambda function – Anil Bhaskaran Aug 10 '20 at 16:55