首先,support for HTTP/0.9 has been completely removed in Jetty 9.3+。
让我们看看行为是什么......
Jetty Distribution 9.2.7.v20150116,运行演示库:
普通 HTTP/1.0 请求:
$ printf "GET / HTTP/1.0\r\n\r\n" | nc localhost 8080
HTTP/1.1 200 OK
Set-Cookie: visited=yes
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Accept-Ranges: bytes
Content-Type: text/html
Last-Modified: Sat, 17 Jan 2015 00:25:03 GMT
Content-Length: 2773
Server: Jetty(9.2.7.v20150116)
<html xmlns=\ "http://www.w3.org/1999/xhtml\" xml:lang=\"en\">
那里有标头,看起来也像 HTTP/1.0 响应标头。
普通 HTTP/1.1 请求:
$ printf "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n" | nc localhost 8080
HTTP/1.1 200 OK
Set-Cookie: visited=yes
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Accept-Ranges: bytes
Content-Type: text/html
Last-Modified: Sat, 17 Jan 2015 00:25:03 GMT
Content-Length: 2773
Connection: close
Server: Jetty(9.2.7.v20150116)
<html xmlns=\ "http://www.w3.org/1999/xhtml\" xml:lang=\"en\">
看起来也很正常。
甚至包括 HTTP/1.1 特定的标头。
现在让我们试试嵌入 CRLF 的 HTTP/1.0:
$ printf "GET /\r\nHTTP/1.0\r\n\r\n" | nc localhost 8080
<html xmlns=\ "http://www.w3.org/1999/xhtml\" xml:lang=\"en\">
没有响应头。
为什么会这样?
嗯,Jetty 没有可以确定的 HTTP 版本,因此没有可以响应的有效标头集。所以它响应没有标题。令人惊讶的是 1.0 之前的 HTTP 规范的行为方式。
现在让我们试试 Jetty Distribution 9.3.x,以及具有相同 CRLF 问题的演示基础配置。
$ printf "GET /\r\nHTTP/1.0\r\n\r\n" | nc localhost 8080
HTTP/1.1 400 HTTP/0.9 not supported
Content-Length: 0
Connection: close
Server: Jetty(9.3.0-SNAPSHOT)
现在,在 HTTP/2 指日可待的现代时代,这更有意义。