Table of Contents
Today, I’ll share with you how to determine the size of the HTTP response header.
The problem I encountered
Last week one of my systems encountered the following error.
When a user send a resquest POST, a 502 error occurs.
I checked the log on the server, I received the following log.
2019/04/02 09:23:33 [error] 2962#2962: *56257144 upstream sent too big header while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: domain.com, request: "POST /URI HTTP/2.0", upstream: "http://xxx.xxx.xxx.xxx:80/URI", host: "domain.com", referrer: "https://domain.com/"You sympathize when I have to hide IP and domain and URI information in the log above.
Why did such an error occur?
The size of the HTTP response header
According to a Chromium document (this is Chrome’s open source), normally the size of the HTTP header will be about 700-800 bytes.
Uncompressed request and response headers. Request headers today vary in size from ~200 bytes to over 2KB. As applications use more cookies and user agents expand features, typical header sizes of 700-800 bytes is common.
You can read more about it at the following link.
How to determine the size of the HTTP response header
We now know that header are usually 1KB in size. I checked my system, I’m leaving it to be 16KB. So why is it still failed.
Log reported that the header is too large. Now I will find a way to determine the size of the header.
Follow an article that I refer to. There is a command that can be used to count the number of bytes of the header.
curl -s -w \%{size_header} -o /dev/null http://domain.comNow I try to run with the Google website.

You see the results are 775, 773 and 781 bytes.
Note: Results may vary by browser.
You can get different response headers depending on the client, i.e. the browser can request capabilities (gzip compression, keep-alives, etc.) that affect the headers in the response, so you cannot assume testing with browser and curl will give you the exact same headers from the server.
Conclusion
This article, just a personal experience of mine. It may be somewhat useful. You often consider as a reference channel.
(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).