Closed danechitoaie closed 5 months ago
That's because all status codes do not have a canonical reason. For instance, StatusCode::from_u16(220)
would be valid, but it doesn't have a known reason phrase.
Yes, makes sense. But still feels weird when using the normal, default, well established status codes. 99% of the cases people will work with those statuses, when for sure they will have a canonical reason. And just for those 1% of the cases when people build some unusual statuses we have to add additional boiler plate.
Maybe there can be a way so that when using a default predefined status to have a method to get the text/canonical reason that returns its &str directly? And only when someone builds a custom one ::from_u16(...)
to have option result?
Just an idea, but if it's not possible and it is what it is then we'll have to learn deal with it.
That would require a separate type, which can only represent known status codes.
Regarding the reason phrase, for what it's worth, the HTTP specifications have deprecated them, and they do not exist in HTTP/2 or 3.
Why does canonical_reason() return a Option?
It feels a bit weird that if I do:
I also have to check if it's Some, or None to actually get the "Bad Request" string when I know for sure it exists as otherwise I wouldn't been able to do
StatusCode::BAD_REQUEST
.Is there any other cleaner way to get that value?