Http response code for invalid / missing host name

let's say I have ip 1.2.3.4 and I matched it with the names

 folk.dude.cool homie.dude.cool bro.dude.cool pal.dude.cool buddy.dude.cool 

I check the value of the Host header on my http server to redirect the request to the appropriate module.

Now, what HTTP response code should ( 400? 502? ) Respond to the client when the value with the Host header is missing or invalid? I note that I like to display the error page, rather than forwarding it by default.

thanks.

+5
source share
2 answers

This is a wrong message, thus 400.

+3
source

Julian is right:

RFC 2616 - 14.23 Host

... The client MUST include the host header field in the entire HTTP / 1.1 Request message. If the requested URI does not contain the Internet host name for the requested service, the host header field MUST be set to blank. An HTTP / 1.1 proxy MUST provide to request a message that it contains an appropriate host header that identifies the request requested by the proxy. All HTTP / 1.1 Internet servers MUST respond with a 400 (invalid request) status code to any HTTP / 1.1 message that lacks a host field header.

When you have questions with the protocol, the RFCs are a bit dry to read, but very informative.

+3
source

All Articles