What is the maximum length of a URL in apache? Where is it documented, and is it configurable?
I'm implementing an openid identity provider, and would like to know the limitations I'm up against. I know about the 2048 byte path limit on Internet Explorer. That can be handled specially using user agent detection. Other browsers have much higher URL limits.
So what I'm interested in is apache server limits when coding an application.
The default limit for the length of the request line is 8190 bytes (see LimitRequestLine
directive). And if we subtract three bytes for the request method (i.e. GET
), eight bytes for the version information (i.e. HTTP/1.0
/HTTP/1.1
) and two bytes for the separating space, we end up with 8177 bytes for the URI path plus query.
- Internet Explorer: 2,083 characters, with no more than 2,048 characters in the path portion of the URL
- Firefox: 65,536 characters show up, but longer URLs do still work even up past 100,000
- Safari: > 80,000 characters
- Opera: > 190,000 characters
- IIS: 16,384 characters, but is configurable
- Apache: 4,000 characters
From: http://www.danrigsby.com/blog/index.php/2008/06/17/rest-and-max-url-size/
The official length according to the offical Apache docs is 8,192, but many folks have run into trouble at ~4,000.
MS Internet Explorer is usually the limiting factor anyway, as it caps the maximum URL size at 2,048.
Here's a bash script to check the maximum limit of a remote server (uses curl and perl).
You just need some kind of an url that can be extended with 'x' and always return 200 (or adapt it to your needs). At some point it will break and the script will display the max length.
Here's the code:
url='http://someurl/someendpoint?var1=blah&token='
ok=0
times=1
while :; do
length=$((times+${#url}))
echo trying with $length
token=$(perl -le 'print "x"x'$times)
result=$(curl -sLw '%{http_code}' -o /dev/null "${url}${token}")
if [[ $result == 200 ]]; then
if [[ $ok == $times ]]; then
echo "max length is $length"
break
fi
ok=$times
times=$((times+1024))
else
times=$(((times+ok)/2))
fi
done
Allowed default size of URI is 8177 characters in GET request. Simple code in python for such testing.
#!/usr/bin/env python2
import sys
import socket
if __name__ == "__main__":
string = sys.argv[1]
buf_get = "x" * int(string)
buf_size = 1024
request = "HEAD %s HTTP/1.1\nHost:localhost\n\n" % buf_get
print "===>", request
sock_http = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock_http.connect(("localhost", 80))
sock_http.send(request)
while True:
print "==>", sock_http.recv(buf_size)
if not sock_http.recv(buf_size):
break
sock_http.close()
On 8178 characters you will get such message: HTTP/1.1 414 Request-URI Too Large
The default limit for the length of the request line is 8192 bytes = 8* 1024. It you want to change the limit, you have to add or update in your tomcat server.xml the attribut maxHttpHeaderSize.
as:
<Connector port="8080" maxHttpHeaderSize="65536" protocol="HTTP/1.1" ... />
In this example I set the limite to 65536 bytes= 64*1024.
Hope this will help.
来源:https://stackoverflow.com/questions/1289585/what-is-apaches-maximum-url-length