hyperium / h2

HTTP 2.0 client & server implementation for Rust.
MIT License
1.34k stars 269 forks source link

fix: avoid protocol error for request with host header #679

Closed everpcpc closed 1 year ago

everpcpc commented 1 year ago

ref: #548 https://github.com/seanmonstar/reqwest/issues/1809

http2 server in google is strict with headers, and a request with HOST in header fields would result in PROTOCOL_ERROR, which is not able to be handled well in hyper and other upper http client libraries.

The ":authority" pseudo-header field conveys the authority portion (Section 3.2 of [RFC3986]) of the target URI (Section 7.1 of [HTTP]). The recipient of an HTTP/2 request MUST NOT use the Host header field to determine the target URI if ":authority" is present.

seanmonstar commented 1 year ago

Thanks for the PR!

As I mentioned in the linked reqwest issue, since it's legal to send both an :authority and host header, with the spec even explicitly saying "intermediaries MAY forward them on", then h2 should not remove them.