hyperium / hyper

An HTTP library for Rust
https://hyper.rs
MIT License
14.42k stars 1.59k forks source link

Consider converting `h2` errors to hyper's error kinds #2564

Open hawkw opened 3 years ago

hawkw commented 3 years ago

Currently, when the h2 crate returns an error, that error is wrapped by Hyper with error::Kind::Http2. However, several of h2s errors have analogous semantics to Hyper's error kinds. For example, h2 will return a "user error: header too big" error when encountering a header that's too large, and this could (potentially) be mapped to Hyper's Kind::Parse(Parse::TooLarge). This would be nice since it would make it possible for users to handle specific error cases the same way regardless of whether they occurred on an HTTP/1 or HTTP/2 connection.

I think implementing this might require changes in h2 as well to expose more information about UserErrors --- currently, the UserError type is private, and h2 only allows determining whether an error is a user error, and formatting it...

seanmonstar commented 3 years ago

Yea, the premise seems reasonable. I think the more general question, that of what "kinds" to even expose programmatically (also mentioned in https://github.com/hyperium/hyper/pull/2504#issuecomment-843661471), is also worth answering. Maybe here, maybe in a separate issue. I don't know the answer.

hawkw commented 3 years ago

In this case in particular, we want to be able to determine when a header value is too large, h2 considers this a "user error" and says that its "user errors" are "errors caused by a user of the library", but since linkerd is a proxy, the too-large header was recieved from a client, and we want to return a 4xx error code in that case.

In the general case, it's definitely worth some more thought about what an appropriate level of granularity is, though.