如何增加Tomcat Java的头大小限制

2cmtqfgy  于 2022-11-13  发布在  Java
关注(0)|答案(2)|浏览(196)

查看https://tomcat.apache.org/tomcat-9.0-doc/config/http.html,我发现8 KB是Tomcat Apache中头大小的默认限制。
当我使用超过默认8 KB的标头发出请求时,日志显示以下内容:Dec 30, 2019 1:59:26 PM org.apache.coyote.http11.Http11Processor service INFO: Error parsing HTTP request header Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level. java.lang.IllegalArgumentException: Request header is too large at org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:720) at org.apache.coyote.http11.Http11InputBuffer.parseHeader(Http11InputBuffer.java:867) at org.apache.coyote.http11.Http11InputBuffer.parseHeaders(Http11InputBuffer.java:563) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:311) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:836) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1839) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)
我的Java项目在/webapp/WEB-INF中没有server.xml,只有web.xml。我尝试创建一个server.xml并添加以下内容,如thread中所述:<?xml version='1.0' encoding='utf-8'?> <Connector port="8080" protocol="HTTP/1.1" maxHttpHeaderSize="65536" maxPostSize="4194304" URIEncoding="UTF-8"/>//webapp/WEB-INF
如何增加默认大小限制?我想设置为16 KB。
提前感谢=)
PS:我是Tomcat/Java世界的新手,如果我犯了一个可怕的错误,我很抱歉

rkkpypqq

rkkpypqq1#

API doc似乎这一个

Tomcat t = new Tomcat();
t.getConnector().setAttribute("maxHttpHeaderSize",65536);

可能是一个有效的解决方案。

tf7tbtn2

tf7tbtn22#

编辑Tomcat的server.xml并添加maxHttpHeaderSize="65536"

<?xml version='1.0' encoding='utf-8'?>
<Connector 
        port="8080" 
        protocol="HTTP/1.1" 
        maxHttpHeaderSize="65536" 
        maxPostSize="4194304"
        URIEncoding="UTF-8"/>

相关问题