Home
/
Website Help
/
How to Fix HTTP Error 431 “Request Header Fields Too Large”

How to Fix HTTP Error 431 “Request Header Fields Too Large”

Have you ever stumbled upon the HTTP error 431 “Request Header Fields Too Large”? While not as common as other HTTP status codes, it’s still prevalent enough to cause trouble for a large number of users.

You might be one of them, and wondering how to deal with it. Well, look no further—this article will shed light on HTTP error 431, what usually causes it, and how to fix it. We will also share insights into what tools to use to troubleshoot it and the best practices to avoid it in your future sessions.

The HTTP status code 431 “Request Header Fields Too Large” is a client-side error indicating that the server can’t process the request your browser sent due to the exceedingly large size of the request’s HTTP header fields. The problem can relate to:

  • the total size of the request headers
  • a single header field that is too large

The request-response model is the foundation of the HTTP protocol powering the Internet. Each time you visit a page, submit a form, click on a button, etc, your browser sends a request to the web server that hosts the website you are on. This request contains header fields that define the conditions of the communication and hold important client information. The server processes the request, finds the appropriate resources, and returns an HTTP response.

Typically, everything goes smoothly, and you simply see a successful representation of the response in the form of a web page, image, video, or another type of web resource. However, if something is wrong with the server or your browser, you’ll likely see an error message informing you of what might have gone amiss.

In the case of an HTTP error 431, the problem is specifically related to the size of the request headers your browser sent to the server—they are too large for the web server, which can’t produce a proper response. Thus, instead of getting to the requested resource, you see an error message like the one below.

HTTP Error 431 "Request Header Fields Too Large"

What Causes the HTTP Error 431

The underlying problem of the HTTP error 431 is the exceedingly large headers of an HTTP request. But what can cause the headers to grow so large? Various issues can contribute to the 431 status code. We will examine the most common ones.

  • Oversized Cookies: Cookies are small pieces of data that your browser stores to remember preferences and login information about different websites. When you revisit such a website, they are included in the request headers.
    However, when there are too many cookies, and they become too large, they can cause issues. Cookies add to the size of the request headers, and when combined, they can exceed the server’s capacity to process them.
  • Long URL Query Parameters: URL query parameters are the bits of information added to a URL to pass data to the server. Websites typically include them in referrer URL links for tracking or analytics purposes.
    While the websites provide the instructions for generating these parameters, the browser is responsible for constructing the final URL. If the parameters become excessively long, it can lead to issues like HTTP Error 431, where the server is unable to process the requested URL due to the size of its headers.
  • Server Limits: If a website’s server doesn’t accommodate larger headers, it might reject the requests, resulting in the HTTP 431 error.
  • Excessive Custom Headers: Some applications or websites (especially those containing custom code) may instruct clients to generate custom headers for their requests. If there are too many headers, or they contain too much data, the server might not be able to handle them properly.

How to Troubleshoot HTTP Error 431

Before fixing HTTP error 431, it is best to examine what exactly causes it. This way, you will commit to the most appropriate and immediate solution.

Start by identifying whether the problem is on the client side (your browser) or the server side (the website). Try accessing the website from a different browser or device.

If the error persists, it’s likely a server-side issue. As the website owner, you can check the server error logs. These logs can provide valuable insights into what’s going wrong.

Server error logs in Site Tools

However, if the error disappears, your browser might be the culprit. To examine what’s happening on the back-end, you can examine the requests in your browser’s Dev Tools console.

HTTP error 431 in Chrome Dev Tools

How to Fix HTTP Error 431

Once you have a better understanding of the underlying problem, you can start fixing it. Here are the common actions to remedy the “Request Header Fields Too Large” response status code.

How to Fix HTTP Error 431 “Request Header Fields Too Large”

Clear Browser Cookies and Cache

Clearing the browser cache and cookies is one of the first things you should do when you encounter the HTTP 431 error. You’ll wipe out any outdated or unnecessary data that might have been making your request headers too large.

Clearing browsing data depends on your chosen browser. Below, you’ll find detailed steps for different browsers and devices.

Keep in mind that if you opt to delete all cookies, you’ll be logged out of all websites. You can select to delete only the cookies for the website that is giving you trouble. Here are the steps to do so on Chrome:

  1. Click on the kebab menu and select Settings.
  2. Open the Privacy and security section.
  3. Choose Third-party cookies.
    Third-party cookies in Chrome
  4. Select See all site data and permissions.
    See all site data and permissions in Chrome
  5. Find the website in the list, and click on the Trash icon. If you don’t see it, type the website name in the Search box in the top right corner.
    Deleting a website's data
  6. In the following pop-up window, confirm by pressing the Delete button.
    Confirm deleting site data in Chrome

Adjust the URL Query Parameters

Albeit quite useful, URL query parameters can make the URL you open so long that the server refuses it and returns the HTTP error 431.

Below is an example of a URL with query parameters for the domain yourdomain.com.

https://www.yourdomain.com/?referrer=https%3A%2F%2Fwww.yourdomain.com%2Fsearch%3Fquery%3Dbest%2Brunning%2Bshoes%26category%3Dfootwear%26brand%3Dnike%26color%3Dblue%26size%3D10%26price_min%3D50%26price_max%3D150%26sort%3Dpopularity%26availability%3Din_stock%26user_id%3D12345%26session_id%3Dabcde12345%26referrer%3Dgoogle%26utm_source%3Dnewsletter%26utm_medium%3Demail%26utm_campaign%3Dspring_sale%26utm_content%3Dtop_deals%26tracking_id%3Dxyz789%26affiliate_id%3Dpartner123%26coupon_code%3DSPRING20

Obviously, the URL in this example is excessively long due to the numerous query parameters. To check if the URL length is causing the HTTP error 431, delete all parameters from the ? sign to the end of the address. Then, visit the website with the base domain name address yourdomain.com.

Deleting URL query parameters

If the error affects your own website and you use long URLs for tracking or analytics, this is not a permanent solution. Consider shortening the tracking/referrer URLs on your website to prevent visitors from receiving the HTTP 431 “Request Header Fields Too Large” error code.

If your website is WordPress-based, shortening the URL addresses is quite easy—there are numerous plugins offering this feature. Some of them include URL Shortify, Bitly, etc.

Using WordPress plugins to shorten the URL query parameters

Modify Your Website’s Code

This next step might prove more difficult, but it may be unavoidable: review your website’s custom code. Some of its functions may instruct clients to post larger request headers, leading to the 431 error code.

The most important points to consider are:

1. Limit the Use of Cookies

Limit the number of cookies your site sets. Ensure that cookies are only used when necessary and that their size is minimized. Consider using session storage or local storage for data that doesn’t need to be sent with every request.

2. Streamline URL Parameters

Simplify URLs by removing unnecessary parameters. Use URL shortening techniques or encode parameters efficiently to keep URLs concise.

3. Consolidate and Minify CSS and JavaScript

While CSS and JavaScript files themselves don’t directly affect header size, the way they are loaded can. Minifying these files reduces the need for multiple requests, which can indirectly reduce the complexity and size of headers.

4. Optimize Header Information

Review the headers your server sends and receives. Remove any redundant or unnecessary headers. Ensure that custom headers are short and only included when absolutely necessary. This reduces the overall header size.

5. Implement Efficient Session Management

Sessions can contribute to large headers if session identifiers are lengthy or numerous. Use efficient session management practices to keep session identifiers short and ensure that only essential session data is included in headers.

6. Use Compression for Headers

While Gzip compression is typically used for response bodies, some servers support compressing headers as well. Check if your server supports this feature and enable it to reduce the size of headers.

Brotli and Gzip compressions are enabled by default on all SiteGround servers. For more information, read this blog post about the differences between Brotli and Gzip compression.

Review and Adjust Your Website’s Cookie Policy

Cookies allow you to provide a unique journey and a great user experience for every visitor to your website. However, if left unchecked, cookie policies can force too many cookies in visitors’ browsers. Eventually, this excessive website data can overburden their request headers, leading to HTTP error 431.

Carefully review your cookie policies—they may be facilitated by custom code or a plugin (for WordPress). Consider adjusting the cookie settings to ensure they generate a manageable number of cookies.

Conclusion

The HTTP status code 431 “Request Header Fields Too Large” is a client-side error indicating that the web server could not process your request headers due to their large size. It can be annoying, but it’s definitely not insurmountable. Fixing it requires optimizing your website’s code, effectively managing cookie policies, and regularly cleaning your browser cookies.

Share This Article