48

And is it configurable? Can I set up Tomcat so that a URL with, say, 200K of query params goes through successfully to the contained servlet?

Yes, I know one should use POST when you have lots of data; that's a less pleasant option in this particular case. The contained application (a search engine) expects a GET request to perform a search.

drAlberT
  • 10,871
  • 7
  • 38
  • 52
Michael Gundlach
  • 1,261
  • 1
  • 9
  • 7

4 Answers4

68

You can edit tomcat/conf/server.xml's HTTP/1.1 Connector entry, and add a maxHttpHeaderSize="65536" to increase from the default maximum of 8K or so, to 64K. I imagine that you could up this number as high as necessary, but 64K suffices for my needs at the moment so I haven't tried it.

<Connector port="8080" maxHttpHeaderSize="65536" protocol="HTTP/1.1" ... />
Michael Gundlach
  • 1,261
  • 1
  • 9
  • 7
  • 3
    Very useful, solved my problem with Solr. Seems we were scratching on the default 8192 limit in the `server.xml` config, without noticing, and suddenly hit it. Painful gotcha: nothing nowhere was logged about that, the connections were silently dropped (I don't recall the HTTP Status anymore). I stumbled over the documentation at http://tomcat.apache.org/tomcat-5.5-doc/config/http.html before, however I didn't associate the `maxHttpHeaderSize` by its name nor its description to be related to the GET request query parameters itself too. – mark Mar 16 '10 at 11:49
  • We also just hit the same limit in Solr, nothing but a blank white page... :( The maxHttpHeaderSize did the trick. – user85116 Sep 27 '12 at 15:37
  • I think the maxHttpHeaderSize="100000" is not possible, it should be in multiply by 1024. I have changed the maxHttpHeaderSize="1048576" which is 1024*1024 and it is still not working. –  Jan 11 '13 at 07:40
  • 4
    An accepted answer, "maxHttpHeaderSize="65536" **does not work** It worked before because of **bug** in Tomcat. URL/URI has nothing to do with HTTP Headers. – Fuad Efendi Sep 11 '15 at 18:08
  • 1
    @FuadEfendi what IS the maximum size now then? – mjaggard Jul 20 '18 at 09:01
  • Original question was "what is the maximum size of URL". HTTP protocol doesn't have "URL"; instead, it has "host" part, and "method" (which could be GET, POST, PUT, etc.); if you need *huge* method use POST which doesn't have any limitations. Server implementations are vendor-specific. Tomcat v.8 uses 2 megabytes for POST (default; but you can configure it 'unlimited'); and 8 kilobytes for GET (default). When you need 'unlimited' POST? For example, if you submit huge HTML FORM with a lot of key-value pairs. – Fuad Efendi Jul 15 '20 at 03:09
  • @FuadEfendi let's say I am in a scenario where the type of method cannot be changed from `GET` to `POST`. In an event like above, is there any way to configure the max URL lengh in tomcat? – Kasun Siyambalapitiya Jan 19 '22 at 19:39
6

The length of an HTTP GET request is not enforced by RFC2616, as Microsoft reports for its IE max length support page.

So, the maximum GET length is a client (browser) related issue. If your app is used by people you can force to use a given browser then you can simply find what is the length this browser support.

In every case I suggest a look to the Wikypedia page about those browser related issues on the Query string (the part of the request bringing parameters for server side apps, the one following the "?" eventually present in a request.

Of course maybe tomcat will put a limit too, on the server side. RFC says:

Servers MUST be able to handle the URI of any resource they serve, and SHOULD be able to handle URIs of unbounded length if they provide GET-based forms that could generate such URIs. A server SHOULD return 414 (Request-URI Too Long) status if a URI is longer than the server can handle (see section 10.4.15).

so you can easily test if Tomcat has a limit and find out what this limit is simply using different requests starting with a very long one giving the error and going down by one half. Then use bisection method to fast find the exact value.

drAlberT
  • 10,871
  • 7
  • 38
  • 52
  • Albert, I was aware that Tomcat had a limit out of the box (something like 8K); I wondered if there were a limit that even configuration could not overcome. – Michael Gundlach Aug 24 '09 at 17:14
2

For AJP connector, you need to adjust the packetSize attribute:

<Connector port="8009" 
    protocol="AJP/1.3" 
    packetSize="65536" />
1615903
  • 124
  • 7
  • 1
    If you are using mod_proxy you need to set `ProxyIOBufferSize 65536` in your httpd config too. – suicide Jun 19 '17 at 17:00
1

You can change the config at Tomcat server ( ..\Tomcat 6.0\conf\server.xml )

< Connector port="8983" maxHttpHeaderSize="100000" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />