]> git.nbdom.net Git - nb.git/commitdiff
lib/perl/NB/CGI.pm
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 27 Nov 2023 00:05:34 +0000 (01:05 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 27 Nov 2023 00:05:34 +0000 (01:05 +0100)
lib/perl/NB/CGI.pm

index 2fc46067f712b24423a3aee5fc78839f18273e47..ccd1760673935060cab03cf9af4b0d9f171f97aa 100644 (file)
@@ -85,9 +85,103 @@ sub textOutput {{
        };
 }}
 
+sub header_status {
+       my %status = (
+               100 => "Continue",
+               101 => "Switching Protocols",
+               102 => "Processing",
+               103 => "Checkpoint",
+               200 => "OK",
+               201 => "Created",
+               202 => "Accepted",
+               203 => "Non-Authoritative Information",
+               204 => "No Content",
+               205 => "Reset Content",
+               206 => "Partial Content",
+               207 => "Multi-Status",
+               208 => "Already Reported",
+               226 => "IM Used",
+               300 => "Multiple Choices",
+               301 => "Moved Permanently",
+               302 => "Found",
+               303 => "See Other",
+               304 => "Not Modified",
+               305 => "Use Proxy",
+               306 => "Switch Proxy",
+               307 => "Temporary Redirect",
+               308 => "Permanent Redirect",
+               400 => "Bad Request",
+               401 => "Unauthorized",
+               402 => "Payment Required",
+               403 => "Forbidden",
+               404 => "Not Found",
+               405 => "Method Not Allowed",
+               406 => "Not Acceptable",
+               407 => "Proxy Authentication Required",
+               408 => "Request Time-out",
+               409 => "Conflict",
+               410 => "Gone",
+               411 => "Length Required",
+               412 => "Precondition Failed",
+               413 => "Payload Too Large",
+               414 => "URI Too Long",
+               415 => "Unsupported Media Type",
+               416 => "Range Not Satisfiable",
+               417 => "Expectation Failed",
+               418 => "I'm a teapot",
+               419 => "I",
+               420 => "Method Failure",
+               421 => "Misdirected Request",
+               422 => "Unprocessable Entity",
+               423 => "Locked",
+               424 => "Failed Dependency",
+               426 => "Upgrade Required",
+               428 => "Precondition Required",
+               429 => "Too Many Requests",
+               431 => "Request Header Fields Too Large",
+               440 => "Login Time-out",
+               444 => "No Response",
+               449 => "Retry With",
+               450 => "Blocked by Windows Parental Controls",
+               451 => "Unavailable For Legal Reasons",
+               495 => "SSL Certificate Error",
+               496 => "SSL Certificate Required",
+               497 => "HTTP Request Sent to HTTPS Port",
+               498 => "Invalid Token",
+               499 => "Client Closed Request",
+               500 => "Internal Server Error",
+               501 => "Not Implemented",
+               502 => "Bad Gateway",
+               503 => "Service Unavailable",
+               504 => "Gateway Time-out",
+               505 => "HTTP Version Not Supported",
+               506 => "Variant Also Negotiates",
+               507 => "Insufficient Storage",
+               508 => "Loop Detected",
+               509 => "Bandwidth Limit Exceeded",
+               510 => "Not Extended",
+               511 => "Network Authentication Required",
+               520 => "Unknown Error",
+               521 => "Web Server Is Down",
+               522 => "Connection Timed Out",
+               523 => "Origin Is Unreachable",
+               524 => "A Timeout Occurred",
+               525 => "SSL Handshake Failed",
+               526 => "Invalid SSL Certificate",
+               527 => "Railgun Error",
+               530 => "Site is frozen",
+               599 => "Network connect timeout error",
+       );
+       my $status = shift;
+       return '' unless $status;
+  $status = $status." ".$status{$status} if $status{$status};
+  return ($ENV{SERVER_PROTOCOL}||'HTTP/1.1')." $status\r\n";
+}
+
 sub header {
   my($self,@p) = &CGI::self_or_default(@_);
-  my $status = '200 OK';
+  # NB 27.11.23 my $status = '200 OK';
+  my $status = '';
 
   if (!&CGI::nph())
   {
@@ -107,11 +201,10 @@ sub header {
   # NB 26.11.23 }
 
   my @head = ();
-       $ENV{SERVER_PROTOCOL} ||= 'HTTP/1.1';
-  #push @head,$ENV{SERVER_PROTOCOL}." $status\r\n";
-  push @head,$ENV{SERVER_PROTOCOL}." $status";
-  #delete $_->{'status'};
   push @head,&CGI::header(@p);
+  #unshift @head,($ENV{SERVER_PROTOCOL}||'HTTP/1.1')." $status"
+  unshift @head,header_stats($status)
+       if $status and @head and !&CGI::nph;
   return join($CGI::CRLF,@head);
 }