hyperium / http

Rust HTTP types
Apache License 2.0
1.14k stars 284 forks source link

HeaderValue::to_str returns an error for valid unicode strings #527

Open lilyball opened 2 years ago

lilyball commented 2 years ago

HeaderValue::to_str() returns an error if the header value contains any byte that's not "visible ASCII" (though this is misleading as \t is legal even though it's not visible). This is weird, it should just return a string if it contains a valid string regardless of the contents. We already know it doesn't contain illegal bytes (as that's checked upon creation of HeaderValue) so we don't need to check again, and there's no reason to disallow unicode characters when getting the string representation.

I think the right thing here is to just replace the implementation with std::str::from_utf8(), and replace ToStrError with a pub use std::str::Utf8Error as ToStrError for backwards compatibility.

Also see #519.