Skip to content

Instantly share code, notes, and snippets.

@pangyre
Last active June 5, 2018 01:54
Show Gist options
  • Save pangyre/39226b024e9e536d054fddd8debd33d1 to your computer and use it in GitHub Desktop.
Save pangyre/39226b024e9e536d054fddd8debd33d1 to your computer and use it in GitHub Desktop.
Tool to compare Wikipedia's current understanding of HTTP status codes in Perl's HTTP::Status
#!/usr/bin/env perl
use strictures;
use XML::LibXML;
use HTTP::Status "status_message";
print "Checking HTTP::Status version ",
HTTP::Status->VERSION, $/, $/;
my $page = do { local $/; <DATA> };
my $dom = XML::LibXML->load_html( string => $page );
my %code_message;
for my $dt ( $dom->findnodes('//dt') )
{
my ( $code, $message ) = $dt->textContent
=~ m{ \A (\d\d\d) \s+ (.+) }x;
push @{$code_message{$code}}, $message;
}
for my $code ( sort keys %code_message )
{
if ( my $message = status_message($code) )
{
# print " HTTP::Status knows $code -> $message\n";
}
else
{
print "Nothing known about $code ";
if ( @{ $code_message{$code} } > 1 )
{
print "[MULTIPLE DEFINITIONS]\n";
printf("%23s -> %s\n", "", $_) for @{ $code_message{$code} };
}
else
{
print "-> ", $code_message{$code}->[0], $/;
}
}
}
__DATA__
Insert the raw HTML of https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
NB: Compare with http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
Script output as of this date-
Checking HTTP::Status verion 6.13
Nothing known about 103 [MULTIPLE DEFINITIONS]
-> Checkpoint
-> Early Hints
Nothing known about 226 -> IM Used (RFC 3229)
Nothing known about 306 -> Switch Proxy
Nothing known about 420 [MULTIPLE DEFINITIONS]
-> Method Failure (Spring Framework)
-> Enhance Your Calm (Twitter)
Nothing known about 421 -> Misdirected Request (RFC 7540)
Nothing known about 440 -> Login Time-out
Nothing known about 444 -> No Response
Nothing known about 450 -> Blocked by Windows Parental Controls (Microsoft)
Nothing known about 451 [MULTIPLE DEFINITIONS]
-> Unavailable For Legal Reasons (RFC 7725)
-> Redirect
Nothing known about 495 -> SSL Certificate Error
Nothing known about 496 -> SSL Certificate Required
Nothing known about 497 -> HTTP Request Sent to HTTPS Port
Nothing known about 498 -> Invalid Token (Esri)
Nothing known about 499 [MULTIPLE DEFINITIONS]
-> Token Required (Esri)
-> Client Closed Request
Nothing known about 508 -> Loop Detected (WebDAV; RFC 5842)
Nothing known about 520 -> Unknown Error
Nothing known about 521 -> Web Server Is Down
Nothing known about 522 -> Connection Timed Out
Nothing known about 523 -> Origin Is Unreachable
Nothing known about 524 -> A Timeout Occurred
Nothing known about 525 -> SSL Handshake Failed
Nothing known about 526 -> Invalid SSL Certificate
Nothing known about 527 -> Railgun Error
Nothing known about 530 -> Site is frozen
Nothing known about 598 -> (Informal convention) Network read timeout error
Nothing known about 599 -> (Informal convention) Network connect timeout error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment