JAVA -tomcat- Request header is too large

JavaHttpTomcatTomcat7

Java Problem Overview


INFO: Error parsing HTTP request header
 Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Request header is too large
	at org.apache.coyote.http11.InternalInputBuffer.fill(InternalInputBuffer.java:512)
	at org.apache.coyote.http11.InternalInputBuffer.fill(InternalInputBuffer.java:501)
	at org.apache.coyote.http11.InternalInputBuffer.parseRequestLine(InternalInputBuffer.java:171)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:996)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:722

How could I solve this in my spring web application?

I had gone through this thread https://stackoverflow.com/questions/2472905/request-header-is-too-large

Java Solutions


Solution 1 - Java

here is the question, is there any limit in HTTP headers? The Answer is No. there is no limit but web-servers are limiting their incoming request header size even in POST requests therefore we getting 413 (Request header is too large). This limitation is including request line and header fields.

http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestfieldsize

https://tomcat.apache.org/tomcat-5.5-doc/config/http.html

http://nginx.org/en/docs/http/ngx_http_core_module.html#large_client_header_buffers[][4]

https://stackoverflow.com/questions/686217/maximum-on-http-header-values


In my case, I had SpringBoot 1.5.8 and used HTTP POST, however I had to add:

server.max-http-header-size=10000000 

in application.properties.

Solution 2 - Java

Solved! I was using HTTP GET instead of HTTP POST. Technically I have seen HttpGet will have issue if the URL length goes beyond 2000 characters. In that case, it's better to use HttpPost or split the URL. Browsers have limits ranging on the 2kb - 8kb

Tomcat: Request header Too large

Solution 3 - Java

> The maximum size of the request and response HTTP header, specified in > bytes. If not specified, this attribute is set to 4096 (4 KB).

To avoid getting Error parsing HTTP request header error you can increase the following value by doing this.

Go to following location: $TOMCAT_HOME/conf/server.xml

In server.xml change the HTTP/1.1 Connector entry and set the maxHttpHeaderSize to "65536" (64Kb in bytes) as shown below:

<Connector port="8080" maxHttpHeaderSize="65536" protocol="HTTP/1.1" ... />

Or

You can use the POST method it can carry upto 2 megabytes according to Tomcat.

> The maximum size in bytes of the POST which will be handled by the > container FORM URL parameter parsing. The limit can be disabled by > setting this attribute to a value less than or equal to 0. If not > specified, this attribute is set to 2097152 (2 megabytes).

Hope this information would help you..

Solution 4 - Java

With Spring Boot 2.4 in application.properties:

server.max-http-header-size=10MB

Solution 5 - Java

It's not about POST or GET but rather what is the header size limit setup for the Tomcat used by your application.

You can always control and configure that using app properties as below: server.tomcat.max-http-header-size=1024

Where 1024 is in Bytes.

Solution 6 - Java

I know it is an old post. However I think it is good to clarify some bits.

  • Using server.tomcat.max-http-header-size=max_wanted_size parameter you will change the server to accept up to max_wanted_size, but even if you set that to 10Mb the browser will cut your request param to the browser limit size. I have tried in chrome and it seems to be around 150-200kb.
  • The java.lang.IllegalArgumentException is happening in the server and it hasn't any to do with the browser. Hence, changing server.tomcat.max-http-header-size should be good enough and it is happening when using GET method but it can also happen when using POST method (In the POST case maxPostSize parameter should be changed).

Solution 7 - Java

I'll add a different "answer" to this problem: the problem could be too many or too large cookies, in the browser of the user visiting the site giving the error.

While most have (understandably) focused on how to change Tomcat to ALLOW a larger header, I'll point out that in a case where I experienced this error, I was able to use my browser dev tools to see that somehow there was a very large number of cookies being sent to the site which generated the error. (They seemed of a sort that I felt something on the server had been mistaken in creating so many, as they had named that were near duplicates of each other, with dupe values.)

I cleared the cookies for this site (using the browser dev tools), and now I did not get the error. Of course, clearing cookies can cause issues like being logged out of the site, etc. In my case, that was a small price to pay for being able to use the site again.

I leave this in case others may hit it some day, and either be the person getting the error (like I was) or a server admin whose users are reporting it, who could ask them to consider clearing the cookies for their site (there are many ways, of course, and web sites to help).

Solution 8 - Java

Its an old post - but anyone looking to change server.max-http-header-size in latest spring boot (version >=2.1) - Value should be provided in Datasize parsable value e.g - server.max-http-header-size=64KB

Solution 9 - Java

In my case, i was displaying a blob image as a url path <img src="example.com/{extremely-long-base64-encoded-string}"> instead of <img scr="data:;base64,{extremely-long-base64-encoded-string}">

You notice the difference, that's what caused the error INFO: Error parsing HTTP request header java.lang.IllegalArgumentException: Request header is too large

Solution 10 - Java

I got the same error while using a Spring Boot app. I just changed data sending way to using Postman form-data from query param and the problem has been solved.

Solution 11 - Java

I just experienced this problem while trying to debug a web app running con localhost tomcat for NetBeans IDE.

Before I could find any solution, tried from Firefox and did not presented the issue.

Turned out Chrome was sending some cookie value or values and hitting some configured limit.

Just erased cookies for localhost from Chrome's developer tools and problem solved.

Solution 12 - Java

In my case, I had a spring boot app that used to redirect to another jetty app based on the request URL. I had to modify it in both places.

Spring Boot

server.max-http-header-size=20000

Jetty

Set the value for property requestHeaderSize as shown below.

   <Call name="addConnector">
      <Arg>
          <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
            <Set name="host"><Property name="jetty.host" /></Set>
            <Set name="port"><Property name="jetty.port" default="8080"/></Set>
            <Set name="maxIdleTime">300000</Set>
			<Set name="requestHeaderSize">20000</Set>
			<Set name="Acceptors">2</Set>
            <Set name="statsOn">false</Set>
            <Set name="confidentialPort">8443</Set>
			<Set name="lowResourcesConnections">20000</Set>
			<Set name="lowResourcesMaxIdleTime">5000</Set>
          </New>
      </Arg>
    </Call>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSarthak SrivastavaView Question on Stackoverflow
Solution 1 - JavaJayView Answer on Stackoverflow
Solution 2 - JavaSarthak SrivastavaView Answer on Stackoverflow
Solution 3 - JavaDulacosteView Answer on Stackoverflow
Solution 4 - JavaMarkus PscheidtView Answer on Stackoverflow
Solution 5 - JavaAshwin GuptaView Answer on Stackoverflow
Solution 6 - Javakimy82View Answer on Stackoverflow
Solution 7 - Javacharlie arehartView Answer on Stackoverflow
Solution 8 - JavaPoovarasan ManickamView Answer on Stackoverflow
Solution 9 - JavaMAYOBYO HASSANView Answer on Stackoverflow
Solution 10 - JavamenoktaokanView Answer on Stackoverflow
Solution 11 - JavaJahazielView Answer on Stackoverflow
Solution 12 - Javaakimran82View Answer on Stackoverflow