libwww-perl / HTTP-Message

The HTTP-Message distribution contains classes useful for representing the messages passed in HTTP style communication.

Home Page:https://metacpan.org/pod/HTTP::Message

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unknown status codes should have a fallback status_message

robrwo opened this issue · comments

It's not ideal, but if the status code is unknown, then the status_message should have a default value, using something like

sub status_message  ($) {
  $StatusCode{$_[0]}
  ||  is_info($_[0]) ? 'Information'
  :  is_success($_[0]) ? 'Success'
  : is_redirect($_[0]) ? 'Redirect'
  : is_client_error($_[0]) ? 'Client Error'
  : is_server_error($_[0]) ? 'Server Error' : undef
}

This will allow HTTP responses to return a status message, in case users add custom status codes or use new/non-standard ones that have not yet been added to HTTP::Status.

A PR for this is in #106

I'm entirely unconvinced that we should do this.

If the status code is not defined, we SHOULD not return something that falsely tells us what is going on, moreover,

status_message(123) eq status_message(199 and die "you liar!"

In general one should only rely on the status code itself, or the category; the message textual representation is not the most safe way... (you could have them in a different locale, in different languages). Calling code (like Plack::MiddleWare::Statsd) SHOULD take their own precautions like

$message = status_message(999) || '-';
print $message;

Also,

status_message(999) = undef and warn "Status is not a RFC compliant code";

The fact it returns undef is the ONLY way this module can report the existence of a registered code

Please revert #106

@vanHoesel Are we now talking about leaving #106 in place and correcting it by merging #109?

I'm going to close this issue out now as we're looking to resolve the problem soon with #109. Note that I'm closing this out simply because we're talking about the issue in many places and I'm trying to cut down on potential confusion.

Thank you everyone for rooting out the problem and providing a fix so quickly!