n0-computer / iroh

peer-2-peer that just works
https://iroh.computer
Apache License 2.0
2.62k stars 165 forks source link

iroh-net does not send the `Host:` header to the relay #2870

Closed link2xt closed 3 weeks ago

link2xt commented 1 month ago

I am trying to put iroh-relay behind nginx: https://github.com/deltachat/chatmail/issues/445 Current problem is that nginx rejects the requests from iroh-net 0.25.0 with error 400. According to the logs nginx gets GET /relay HTTP/1.1, then header upgrade: iroh derp http, then rejects because client sent HTTP/1.1 request without "Host" header. I cannot make it proxy the request to iroh-relay.

HTTP/1.1 requires the Host: header and it seems to be impossible to make nginx proxy requests that don't have one.

I will try to upgrade iroh-net and see if it resolves the problem. EDIT: upgraded to 0.26.0 so far, and the problem remained. Trying to upgrade to 0.27.0, but it has its own problems: https://github.com/deltachat/deltachat-core-rust/pull/6133

link2xt commented 4 weeks ago

It seems this part of code missies .header(HOST, ...): https://github.com/n0-computer/iroh/blob/f0590be408c8dbe412897525a97a170e694dd650/iroh-net/src/relay/client.rs#L719-L722 The value should be self.url.host_str().

As described in https://docs.rs/hyper/1.5.0/hyper/header/constant.HOST.html "A Host header field must be sent in all HTTP/1.1 request messages. A 400 (Bad Request) status code will be sent to any HTTP/1.1 request message that lacks a Host header field or contains more than one.".