Sarthak Srivastava
Sarthak Srivastava

Reputation: 1518

JAVA -tomcat- Request header is too large

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 Request header is too large

Upvotes: 69

Views: 182700

Answers (13)

Knight Rider
Knight Rider

Reputation: 1216

For Spring Boot 3,

This property is deprecated!!!

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

Use this instead.

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

Upvotes: 9

Imran AK
Imran AK

Reputation: 113

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>

Upvotes: 0

Jahaziel
Jahaziel

Reputation: 227

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.

Upvotes: 0

menoktaokan
menoktaokan

Reputation: 506

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.

Upvotes: 1

Markus Pscheidt
Markus Pscheidt

Reputation: 7331

With Spring Boot 2.4 in application.properties:

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

Upvotes: 18

MAYOBYO HASSAN
MAYOBYO HASSAN

Reputation: 506

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

Upvotes: 0

charlie arehart
charlie arehart

Reputation: 6884

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).

Upvotes: 3

Poovarasan Manickam
Poovarasan Manickam

Reputation: 1

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

Upvotes: 0

Du-Lacoste
Du-Lacoste

Reputation: 12757

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..

Upvotes: 35

Sarthak Srivastava
Sarthak Srivastava

Reputation: 1518

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

Upvotes: 26

Jay Ehsaniara
Jay Ehsaniara

Reputation: 1529

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

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.

Upvotes: 49

kimy82
kimy82

Reputation: 4465

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).

Upvotes: 6

Ashwin Gupta
Ashwin Gupta

Reputation: 940

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.

Upvotes: 8

Related Questions