invalid/missed 主机名的 HTTP 响应代码
Http response code for invalid/missed host name
假设我有 ip 1.2.3.4
并将其映射到以下名称
folk.dude.cool
homie.dude.cool
bro.dude.cool
pal.dude.cool
buddy.dude.cool
我检查我的 http 服务器中的 Host
header 值以将请求转发到相关模块。
现在,当 Host
header 的值丢失或无效时,我应该向客户端响应什么 http 响应代码(400?
,502?
)?我注意到我喜欢显示错误页面而不是转发到默认名称。
谢谢。
这是一条格式错误的消息,因此是 400。
朱利安是正确的:
... 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.
当您遇到协议问题时,RFC 读起来有点枯燥,但信息量很大。
假设我有 ip 1.2.3.4
并将其映射到以下名称
folk.dude.cool
homie.dude.cool
bro.dude.cool
pal.dude.cool
buddy.dude.cool
我检查我的 http 服务器中的 Host
header 值以将请求转发到相关模块。
现在,当 Host
header 的值丢失或无效时,我应该向客户端响应什么 http 响应代码(400?
,502?
)?我注意到我喜欢显示错误页面而不是转发到默认名称。
谢谢。
这是一条格式错误的消息,因此是 400。
朱利安是正确的:
... 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.
当您遇到协议问题时,RFC 读起来有点枯燥,但信息量很大。