hyperium / headers

Typed HTTP Headers from hyper
https://hyper.rs
MIT License
162 stars 84 forks source link

IfMatch succeeds decode without values given (for example) #145

Open FlixCoder opened 1 year ago

FlixCoder commented 1 year ago

Hi!

Axum's change to TypedHeader (via this issue) made it that decode is called on an empty iterator of values. However, IfMatch and probably more headers now always succeed even if the header was not present and return an empty IfMatch(EntityTagRange::Tags("")). It should probably fail if there is no value present.

Thank you!

seanmonstar commented 1 year ago

Whether a certain header type should consider an empty value a header is probably worth discussing in each case. But I did want to point out that there is a method, typed_try_get(), which will return None if the name does not exist.

FlixCoder commented 1 year ago

So you think I should rather open an issue in axum stating that the handling is actually incorrect?

FlixCoder commented 1 year ago

After further discussion and looking at documentation, an empty value should either yield the header's default value or error. For If-Match, I think erroring makes sense, though * as value might be fine, too. An empty tag, like now, seems nonsense to me. The thing is, there was no empty value (iterator with an empty item), there was no value (empty iterator).

jplatte commented 10 months ago

@seanmonstar to be clear (though I don't intend to work on it myself), in the specific case of IfMatch, you'd accept a PR that makes decode return an error when the input is an empty iterator?