h2_backend - no Host header

Given that self-managed HTTP/2 via handlers = [“tls”] is no longer supported, I decided to switch. Previously, I had the following setup

[[services]]
  internal_port = 5202
  protocol = "tcp"
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 1
  [[services.ports]]
    handlers = ["tls"]
    port = "9090"
    tls_options = { alpn = ["h2"] }

I have switched this to the new setup:

[[services]]
  internal_port = 5202
  protocol = "tcp"
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 1
  [[services.ports]]
    handlers = ["tls", "http"]
    port = 9090
    tls_options = { alpn = ["h2"] }
    http_options = { h2_backend = true }

This works. But there is a differnce in the Host header. Previously, I received my.app as the Host, now it is something like 172.19.137.34.

I need to know the original Host. An additional http_service hosted on the same machine receives the correct Host header without problems. I also echoed back the HTTP headers to debug this issue and there is no additional information that could help me discern the original Host.

This was already reported in h2_backend loses incoming request host information , but I can still reproduce it.

Hey @CommonGuy

Yeah, with h2_backend we currently don’t properly forward :authority: pseudo-header. This is on our TODO list, but no ETA at the moment.

We still set Host header even for http/2, though, so it should be available to your app.

Could use share a reproducer that shows the problem, please?

I’ve just tested it with a simple Go app and I see the original host header just fine.

Thank you for the quick answer. Based on my research, it seems that .NET (or rather Kestrel, the webserver) replaces the Host header with the :authority: value completely to prevent mismatched values. That’s why I cannot see the actual Host header. See aspnetcore/src/Servers/Kestrel/Core/src/Internal/Http2/Http2Stream.cs at main · dotnet/aspnetcore · GitHub

So properly setting the :authority: header would be much appreciated

@CommonGuy

Could you share your app’s name, please? If you don’t want to share it publicly, feel free to drop me an email to pavel fly.io.

I’ve just rolled out a fix for this. It’s behind a feature flag which I’m gonna gradually enable for all apps in the coming days. I can switch it on for your app first, if you want.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.