Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve "Invalid character found in the HTTP protocol [HTTP/1.10x0aHost:]"?

After I deployed my SpringBoot project to an AWS EC2 instance, an exception shows up frequently:

2020-07-31 01:56:21.487 DEBUG 7340 --- [nio-8080-exec-1] o.a.tomcat.util.net.SocketWrapperBase    : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@3d89313d:org.apache.tomcat.util.net.NioChannel@11d95ea0:java.nio.channels.SocketChannel[connected local=/172.31.38.151:8080 remote=/198.98.61.139:33842]], Read from buffer: [0]
2020-07-31 01:56:21.487 DEBUG 7340 --- [nio-8080-exec-1] org.apache.tomcat.util.net.NioEndpoint   : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@3d89313d:org.apache.tomcat.util.net.NioChannel@11d95ea0:java.nio.channels.SocketChannel[connected local=/172.31.38.151:8080 remote=/198.98.61.139:33842]], Read direct from socket: [175]

2020-07-31 01:56:21.487  INFO 28770 --- [nio-8080-exec-4] o.apache.coyote.http11.Http11Processor   : Error parsing HTTP request header
 Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in the HTTP protocol [HTTP/1.10x0aHost:]
        at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:560) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:260) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36]
        at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]

It doesn't break the project, and every functionality is running fine. But I don't know if it will cause some problems in the future, so I would like to solve it now.

Could anyone give me some hints about what causes this exception please?

like image 218
powerseed Avatar asked Oct 28 '25 06:10

powerseed


1 Answers

I had the same problem and found it related to a change to Tomcat 8.5 introduced in version 8.5.44. The description on this is Fix: 63578: Improve handling of invalid requests so that 400 responses are returned to the client rather than 500 responses. (markt) (http://tomcat.apache.org/tomcat-8.5-doc/changelog.html#Tomcat_8.5.44_(markt))

In that situation some legacy code making a manual request being made to an HTTP GET endpoint was sending something like:

"GET " + path + " HTTP/1.1\n"

This needed to be changed to:

"GET " + path + " HTTP/1.1\r\n" to fix the problem.

Putting details here for future reference to others with the same issue. Tomcat would have fixed this to be more compliant, that might break legacy code that was not doing the right thing.

like image 53
JohnW Avatar answered Oct 29 '25 21:10

JohnW