apache中URL的最大长度是多少?它在哪里记录,是否可配置?
我正在实现一个openid身份提供程序,并且想知道我遇到的局限性。我知道Internet Explorer上的2048字节路径限制。这可以使用用户代理检测特别处理。其他浏览器的URL限制要高得多。
所以我感兴趣的是编写应用程序时的apache服务器限制。
request line长度的默认限制是8190字节(参见LimitRequestLine
directive)。如果我们减去请求方法的三个字节(即GET
),版本信息的八个字节(即HTTP/1.0
/ HTTP/1.1
)和分隔空间的两个字节,我们最终得到8177个字节用于URI路径加查询。
来自:http://www.danrigsby.com/blog/index.php/2008/06/17/rest-and-max-url-size/
官方长度根据官方Apache文档是8,192,但很多人遇到麻烦在~4,000。
无论如何,MS Internet Explorer通常都是限制因素,因为它将最大URL大小限制为2,048。
这是一个bash脚本来检查远程服务器的最大限制(使用curl和perl)。
你只需要一种可以用'x'扩展的URL,并且总是返回200(或根据你的需要调整它)。在某些时候它会中断并且脚本将显示最大长度。
这是代码:
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
GET请求中允许的默认URI大小为8177个字符。 python中用于此类测试的简单代码。
#!/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()
在8178个字符上,您将收到以下消息:HTTP / 1.1 414 Request-URI Too Large
请求行长度的默认限制是8192字节= 8 * 1024.要更改限制,必须在tomcat server.xml中添加或更新attribut maxHttpHeaderSize。
如:
<Connector port="8080" maxHttpHeaderSize="65536" protocol="HTTP/1.1" ... />
在此示例中,我将限制设置为65536字节= 64 * 1024。
希望这会有所帮助。