JAVA -tomcat- Request header is too large
Asked Answered
M

13

68
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

Maxie answered 27/9, 2016 at 9:1 Comment(4)
Hint: this has nothing to do with eclipse I guess.Dedra
Did you capture the http packets for this request and tried to view the headers?Broder
i think there should be some configuration changes in tomcat irrespective of eclipse @DedraMaxie
I need to know what configuration changes and where i need to make in my spring app or tomcat? @HimanshuMaxie
M
27

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

Maxie answered 27/9, 2016 at 9:27 Comment(0)
I
48

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.

Ipsambul answered 1/12, 2017 at 10:30 Comment(6)
I added MB to the size value 10000000 to get 10000000MB. because it gives the following error Failed to bind properties under 'server.max-http-header-size' to org.springframework.util.unit.DataSize:Leonilaleonine
10000000MB is almost 10TB, are you planning to send 10TB in the header?Ipsambul
I was only pointing out i had to add MB to the value for it to work for me i used 1MBLeonilaleonine
I had to use server.tomcat.max-http-header-size insteadRerun
Just as an FYI, I am pretty sure SpringBoot properties like server.max-http-header-size and 'server.tomcat.max-http-header-size' will only work if you are running an embedded server.Rodman
server.max-http-request-header-size=10000000Subtemperate
R
34

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

Rubble answered 6/4, 2019 at 4:55 Comment(0)
M
27

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

Maxie answered 27/9, 2016 at 9:27 Comment(0)
A
17

With Spring Boot 2.4 in application.properties:

server.max-http-header-size=10MB
Acquiescence answered 4/2, 2021 at 17:11 Comment(0)
C
8

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.

Chowchow answered 12/4, 2017 at 10:30 Comment(2)
Many answers, here, seem to confuse headers and query string/request body.Roomette
For Springboot 2.x server.max-http-header-size=1KBBypath
D
7

For Spring Boot 3,

This property is deprecated!!!

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

Use this instead.

server.max-http-request-header-size=10MB
Dreyfus answered 4/2, 2023 at 16:50 Comment(0)
H
6

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).
Heatherheatherly answered 26/7, 2017 at 10:3 Comment(0)
M
3

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

Malca answered 18/5, 2020 at 2:21 Comment(2)
Thanks a lot for leaving this up. Had exactly same problem with my GeoServer instance.Lawry
Clearing browser cookies also solve my problem, thanks!Legere
H
1

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.

Heger answered 14/9, 2021 at 8:17 Comment(0)
T
0

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

Tavie answered 7/4, 2020 at 23:19 Comment(0)
S
0

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

Siloa answered 18/7, 2020 at 12:9 Comment(0)
S
0

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.

Sadoc answered 29/12, 2021 at 16:2 Comment(0)
W
0

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>
Watcher answered 7/1, 2022 at 9:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.