libwww-perl / HTTP-Message

The HTTP-Message distribution contains classes useful for representing the messages passed in HTTP style communication.
https://metacpan.org/pod/HTTP::Message
Other
28 stars 61 forks source link

Update several status codes to RFC 9110 #197

Closed waterkip closed 6 months ago

waterkip commented 7 months ago

Reference: https://www.rfc-editor.org/rfc/rfc9110.html#name-changes-from-rfc-7231

oalders commented 7 months ago

I'm going to close and re-open to see if that starts CI.

vanHoesel commented 7 months ago

What about the following:

set the %StatusCodes like:

    306 => '(Unused)',                        # RFC 9110: Previously used and reserved
    418 => '(Unused)',                        # RFC 9110: Its official now -sorta
#   419 .. 420
my %compat = (
    I_AM_A_TEAPOT                 => sub {
                                       carp "HTTP Status Code 418 set to \"I'm a Teapot\"\n"
                                       $StatusCode{418} = "I'm a teapot";
                                       418
                                     },
    NO_CODE                       => \&HTTP_TOO_EARLY,
    PAYLOAD_TOO_LARGE             => \&HTTP_CONTENT_TOO_LARGE,
    REQUEST_ENTITY_TOO_LARGE      => \&HTTP_CONTENT_TOO_LARGE,
    REQUEST_RANGE_NOT_SATISFIABLE => \&HTTP_RANGE_NOT_SATISFIABLE,
    REQUEST_URI_TOO_LARGE         => \&HTTP_URI_TOO_LONG,
    UNPROCESSABLE_ENTITY          => \&HTTP_UNPROCESSABLE_CONTENT,
    UNORDERED_COLLECTION          => \&HTTP_TOO_EARLY,
    UNUSED                        => sub {
                                       carp "HTTP Status Code '(Unused)'\n";
                                       000
                                     },
);

That way, for those who fancy the 🫖 , it is still there when once used as HTTP_I_AM_A_TEAPOT. Maybe a nice way to only warn the user once for the teapot, and only set the status code message once ?

Please be advised, that use Carp might be needed, and that whilst looping during '# create mnemonic subroutines ' it will redefine HTTP_UNUSED.

Just some ideas...

haarg commented 7 months ago

I think it would be better to remove the constants for the "unused" codes. That eliminates the ambiguity between 306 and 418.

vanHoesel commented 7 months ago

I think it would be better to remove the constants for the "unused" codes. That eliminates the ambiguity between 306 and 418.

I am totally fine with removing (or preferably not adding) the HTTP_UNUSED and RC_UNUSED.

But unlike non registered codes that will return undef when calling status_message for not registered codes, II think we should return (Unused) for both 306 and 418, for that is what is set to at the IANA registry.

waterkip commented 6 months ago

Any update on this PR?

oalders commented 6 months ago

Close and re-open to kick off CI.

oalders commented 6 months ago

Thanks, @waterkip!