http头中的host字段详解

http头中的host字段详解

Host:客户端指定自己想访问的http服务器的域名/IP 地址和端口号。

今天同事问了一个问题引发了我对http头中host字段的详细思考,总结了以下5条。

1.host字段可以是域名,也可以是ip地址。host字段域名/ip后可以跟端口号,如Host: www.6san.com:8080

2.host可以由程序自定义,某些程序为了防止运营商或防火墙拦截会定义虚假host

3.http1.1中host字段可以是空值,http1.0中可以缺失host字段

4.http响应头中不包含host字段,所以wireshark中http.host过滤到的都是请求包

5.因为http头中的host字段可以由程序自定义,所以host字段的值就会有很多特殊情况,如包含多个’/’字符的HOST头信息,结尾含有”.”等

http头中可以没有host字段吗?

在http 1.1中不能缺失host字段,如果缺失, 服务器返回400 bad request,http1.1中不能缺失host字段,但host字段可以是空值

在http 1.0中可以缺失host字段。

RFC 2616中关于host字段的说明如下:

A client MUST include a Host header field in all HTTP/1.1 request
messages . If the requested URI does not include an Internet host
name for the service being requested, then the Host header field MUST
be given with an empty value. An HTTP/1.1 proxy MUST ensure that any
request message it forwards does contain an appropriate Host header
field that identifies the service being requested by the proxy. All
Internet-based HTTP/1.1 servers MUST respond with a 400 (Bad Request)
status code to any HTTP/1.1 request message which lacks a Host header
field.

6san.com

发表评论