What the HTTP 400 Header Size Error Means
An HTTP Error 400 with the note "the size of the request headers is too long" means the server rejected the request because the cumulative size of HTTP request headers exceeds an internal limit. This is a server-side safeguard, not a browser bug. Common causes include large cookies, many custom headers, deeply nested query strings, or misconfigured reverse proxies and load balancers. The result is a 400 Bad Request response with no page content, often logged as header line size errors in server records.
How HTTP Header Size Limits Work
HTTP specifications do not mandate a universal header size limit; each server, proxy, or application framework sets its own thresholds. When the total size of headers—name, value, and separators—crosses this limit, the server drops the request and returns 400. These limits exist to prevent resource exhaustion, mitigate certain denial-of-service risks, and keep message parsing efficient. Understanding where the limit is enforced (client, intermediate proxy, origin server) is crucial for troubleshooting.
Key Terms in Header Size Errors
- Request headers: HTTP metadata sent by the client to the server.
- Header line size: The byte length of a single header line including name and value.
- Total header size: The aggregate size of all headers plus separators.
- Max header list size: A constraint imposed by servers, proxies, or browsers.
Common Culprits Behind Oversized Headers
Large cookies are the most frequent cause, especially when many cookies are attached to a single domain or when cookie values contain encoded tokens or session data. Custom headers added by analytics, monitoring, or legacy systems can accumulate quickly. Query parameters embedded in the request URL also contribute to header size, as some servers treat them as part of the header list. Misconfigured intermediaries may apply stricter defaults than the origin server, amplifying the problem.
Typical Sources
- Excessive cookies per domain (e.g., tracking, session, third-party tokens).
- Authorization headers with long bearer tokens or encoded certificates.
- Custom headers for tracing, feature flags, or A/B testing.
- URL query strings larger than a few kilobytes.
Where the Limit Is Enforced
Different layers impose their own limits. Browsers may cap header size per request to protect users, though they typically don’t surface precise numbers. Web servers like Nginx and Apache have configurable directives for header buffer sizes and maximum header fields. Reverse proxies and load balancers—such as Cloudflare, AWS ALB, or API gateways—often apply their own thresholds. Application frameworks may also validate header length before processing the request.
Limit Examples by Component (Illustrative)
| Component | Typical Limit | Notes |
|---|---|---|
| Apache (LimitRequestFieldSize) | 8190 bytes default | Per-header buffer limit; adjustable. |
| Nginx (large_client_header_buffers) | 4 buffers of 8k default | Total header buffer cap; can be increased. |
| Cloudflare | Approx. 32 KB combined headers | Edge limit; may vary by plan. |
| IIS | ~16–32 KB default | Configurable via registry and metabase. |
| Browser (typical) | ~8–16 KB practical cap |
How to Diagnose the Error
Begin by reproducing the request with a minimal set of headers and then adding back components incrementally: cookies, custom headers, and query parameters. Use browser developer tools or HTTP clients (cURL, Postman) to inspect header sizes and counts. Check server and proxy logs for specific messages like "header line size" or "buffer overflow." Correlate timestamps to identify whether the issue occurs at the browser, edge, or origin layer. Capture a full request trace to see which hop enforces the limit.
Diagnostic Checklist
- Count and size of all cookies in the request.
- Length of each custom header and Authorization value.
- Total URL length, including query string.
- Headers added by browser extensions or SDKs.
- Documented limits for intermediaries (CDN, API gateway).
Practical Fixes and Mitigations
Reduce header size by consolidating or trimming cookies, removing unnecessary custom headers, and shortening tokens where feasible. Move large state from query strings into the request body for POST/PUT requests. On the server side, increase buffer and limit settings cautiously and monitor the impact on memory and security. For distributed systems, ensure consistent limits across edge and origin, and document acceptable header sizes for clients and third-party integrations.
Actionable Steps
- Audit cookies: remove duplicates, legacy tokens, and limit scope to necessary domains.
- Trim custom headers; avoid embedding large payloads in headers.
- Shorten or offload authorization tokens when possible; prefer cookies or headers with moderate size.
- Adjust server/proxy settings if you control the infrastructure, and test for stability.
- Set internal guidelines for APIs to keep headers under conservative thresholds (e.g., 8 KB total).
Preventing Future Occurrences
Prevent regrowth by establishing standards for cookie usage, token formats, and header policies. Instrument monitoring for header size metrics in logs and synthetic checks. Document limits for external developers if you expose an API. Regularly review third-party scripts and SDKs that inject cookies or headers, as they are a common source of bloat.
When to Escalate or Seek Vendor Support
If the issue persists after tuning cookies, headers, and query strings, involve your platform or hosting provider. CDN and cloud load balancer vendors can advise on their specific limits and help adjust configurations. For API consumers, contact vendors when a required integration consistently hits header size constraints; they may offer alternative endpoints or relaxed limits.
Key Takeaways
- HTTP 400 due to oversized headers is a server protection mechanism, not a browser error.
- Large cookies, many custom headers, and long query strings are the usual suspects.
- Limits vary by server, proxy, and edge layer; you must check each component in path.
- Diagnose by incremental testing and inspecting headers at each hop.
- Fix by reducing header payload, consolidating cookies, offloading state, and tuning server/proxy settings where you have control.