Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Http response code for invalid/missed host name

Tags:

http

dns

let say I have ip 1.2.3.4 and I mapped it to the following names

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

I check the Host header value in my http server to forward the request to the related module.

Now what http response code should I respond(400?, 502?) to client when the value with Host header is missed or invalid? I note I like to show a error page rather to forward to a default name.

thanks.

like image 211
user4872433 Avatar asked May 20 '15 17:05

user4872433


2 Answers

Julian is correct:

RFC 2616 - 14.23 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.

When you've got protocol questions, the RFCs are a little dry to read, but very informative.

like image 93
Rick Buford Avatar answered Sep 28 '22 09:09

Rick Buford


That's a malformed message, thus 400.

like image 26
Julian Reschke Avatar answered Sep 28 '22 08:09

Julian Reschke