为什么在使用类似于 "something.com-xyz" 的 url 时 tomcat returns “400 Bad Request”

Why does tomcat returns "400 Bad Request" while using url which are similar to "something.com-xyz"

如果主机名以 xyx.com-abc 结尾,为什么 Tomcat 版本 7.0.88 会给出“400 Bad Request”错误代码。

出于测试目的,我们假设主机文件中有以下条目

127.0.0.1 hello.hello.hello-erq

然后我们尝试从 curl

访问这个 url

curl -v hello.hello.hello-er:8080

我们得到以下输出

* Rebuilt URL to: hello.hello.hello-er:8080/
*   Trying 127.0.0.1...
* Connected to hello.hello.hello-er (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: hello.hello.hello-er:8080
> User-Agent: curl/7.49.0
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< Server: Apache-Coyote/1.1
< Transfer-Encoding: chunked
< Date: Thu, 20 Dec 2018 19:53:09 GMT
< Connection: close
<
* Closing connection 0

在 url 中使用本地主机时,我们得到

 C:\playground\apache-tomcat-7.0.88-windows-x64\apache-tomcat-7.0.88\bin>curl -v localhost:8080
* Rebuilt URL to: localhost:8080/
*   Trying ::1...
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.49.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Content-Type: text/html;charset=ISO-8859-1
< Transfer-Encoding: chunked
< Date: Thu, 20 Dec 2018 20:00:07 GMT
<

<!DOCTYPE html>

所有 tomcat 配置对于两个测试都是相同的,同样的问题也在开箱即用的香草 tomcat 服务器上复制。

我试图在 tomcat-8 上重现同样的问题,但 url 都在那里工作得很好。我如何才能更深入地挖掘并找出 7.0.88 中此问题的根本原因?

是否有一些我可以启用的额外日志记录以获取有关此问题的更多信息?

或者我唯一剩下的就是拔头发升级?

Tomcat 正在尝试 enforce the domain name specification by refusing your hostname with a hyphen in the TLD. This was deemed a bug in Tomcat and fixed in 7.0.89 (and versions of Tomcat 8.0.x, 8.5.x and 9.0.x released around the same time)

所以看来你只需要一个小的版本bump。