Error: no host specified in headers or uri

I have just start 2 new Nodejs project moved from Heroku, using builder = “heroku/buildpacks:20”. Both are the expressjs sites. Everything seemed to be fine.

But after the site sat for few hours, I take a look at the “Monitoring” screen. There are these logs in the window on both of the projects.

Error: no host specified in headers or uri
Error: no host specified in headers or uri

So why those were logged?

That can happen if you’re using the force_https handler and your app gets an HTTP request without a Host header or the full hostname (http/2) in the URI.

In these situation our proxy returns a 400 response code and we log it.

Am glad this question got asked, as I’ve been wondering the same thing since migrating over.

@jerome Did you mistype your response? Did you actually mean to write “without a Host header or a hostname”? Regardless, would you mind providing some context or background information regarding your response? (Or a pointer to such info?) It isn’t clear to me what the root issue here is. How would an HTTP request ever be received without a hostname? By “hostname”, you mean something akin to “www.google.com”, correct? Thank you in advance.

Yes, jerome meant “without” a hostname.

Things that crawl the internet won’t include a hostname. HTTP 1.0 didn’t require a host header, HTTP 1.1 does. So things that aren’t doing proper HTTP 1.1 are usually the culprit.

This error probably doesn’t affect your app. It probably means some bot from the internet sent a bad request to your IP.

2 Likes

Thank you for this, @kurt ! I suspected as much, but very much appreciate the confirmation.

Right, I did mistype. I’ve edited the response.

What @kurt said is right.

I’d clarify:

  • http/2 requires an :authority pseudo-header that contains the absolute (full) URL
  • http/1.1 requires a Host header
  • http/1 does not require a Host header

Without a definitive “host” value from the request, we can’t build a Location header for the force_https redirect.

2 Likes