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.
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 ofHeaderValue
) 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 replaceToStrError
with apub use std::str::Utf8Error as ToStrError
for backwards compatibility.Also see #519.