jimmitjoo's avatar

HTTP header is larger than 10240 bytes

I have a user reporting this error message: HTTP header is larger than 10240 bytes

After looking around it seems to be a limit on the AWS API Gateway. Is there any way I can minimize this programmatically in Laravel, compressing it or something?

I am not experience it myself, but this is a power user who is working in the application all days long. I asked to clear the cookies and that seems to have solved the problem at least temporarily.

How does I even start to dig into this? Not really that familiar with what is happening behind the size of the Laravel Vapor service.

0 likes
13 replies
Sinnbeck's avatar

Are you putting a lot of things in session ?

jimmitjoo's avatar

@Sinnbeck no not really. Using Laravel Nova, with about 15 different models, but not really changed anything regarding sessions.

When investigating the developer tools, it seems like Nova is saving a ton of stuff in local storage. Does that have an impact on header size?

Sinnbeck's avatar

@jimmitjoo Not to my knowledge now. It is only stuff that goes in the header. But from what I can find online the error also points to session :)

jimmitjoo's avatar

@Sinnbeck yeah I found that too.

But my Session Storage is completely empty. Developer Tools Screenshot

And this is the Cookies. Developer Tools Screenshot

Does not find any errors in the vapor logs either. Possibly there are no logs for the API Gateways? Seems to only be for the Lambda functions.

jimmitjoo's avatar

I asked Taylor about this. He asked me to check if I could try to switch session driver to database, and now it has been working for 2 weeks with no issues. So it was probably something with the session - not sure exactly what though.

azimidev's avatar

I would suggest starting to dig into it by looking at the HTTP header size which is a common restriction imposed by various gateways and servers to prevent Denial-of-Service (DoS) attacks and to manage server resources.

  • Compress header data: add this to .htaccess file:
<IfModule mod_deflate.c>
   AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript
</IfModule>
  • maybe increase the header size limit by accessing AWS API Gateway or Laravel Vapor
azimidev's avatar

@jimmitjoo Ah i see you are right then you have left with compressing the data before sending it, splitting the data into smaller chunks and sending it in multiple requests, or using a different service that allows for larger header sizes.

jimmitjoo's avatar

@webinarincadmin no solution other than asking the user to clear his cookies. He has not been contacting me afterwards and is using my app on a daily basis so I guess it works for him now.

Sorry I cannot give any better solution.

helgesverre's avatar
Level 7

Just want to chime in with my own findings.

This problem occurs because session data is stored in cookies by default on Vapor.

When too much stuff is stored in the session (usually because filament or nova persists filter options or pagination preferences etc in the session), eventually the size exceeds the allowed limit in AWS lambda.

The easy way to fix this is to change the SESSION_DRIVER environment variable to dynamodb or database.

Wrote about this here:

https://helgesver.re/articles/http-header-larger-than-10240-bytes-larvel-vapor

jimmitjoo's avatar

@helgesverre actually that was just what we did in the end. No issues since. Forgot to update this thread tho, so thank you! :)

1 like

Please or to participate in this conversation.