I'm not sure if someone else has contributed something similar, but here's a patch for Protocols.HTTP.Server.Request that provides more informative response codes for almost all of the HTTP responses in widespread use (present in RFCs or not).

--- lib/modules/Protocols.pmod/HTTP.pmod/Server.pmod/Request.pike.orig  Wed Dec 
 9 16:32:20 2009
+++ lib/modules/Protocols.pmod/HTTP.pmod/Server.pmod/Request.pike       Wed Oct 
12 16:46:19 2011
@@ -31,6 +31,79 @@
 // finalize


+constant errors=
+([
+  // Informational
+  100:"100 Continue",
+  101:"101 Switching Protocols",
+  102:"102 Processing", // WebDAV
+  103:"103 Checkpoint",
+  122:"122 Request-URI too long", // a non standard IE7 error
+
+  // Successful
+  200:"200 OK",
+  201:"201 Created, URI follows",
+  202:"202 Accepted",
+  203:"203 Non-Authoritative Information",
+  204:"204 No Content",
+  205:"205 Reset Content",
+  206:"206 Partial Content", // Byte ranges
+  207:"207 Multi-Status", // WebDAV
+  226:"226 IM Used", // RFC 3229
+
+  // Redirection
+  300:"300 Moved",
+  301:"301 Permanent Relocation",
+  302:"302 Found", // a potential alligator swamp. for HTTP/1.1, use 303/307.
+  303:"303 See Other", // temporary redirect, any POST data is received, use 
GET.
+  304:"304 Not Modified",
+  305:"305 Use Proxy",
+  306:"306 Switch Proxy", // Deprecated
+  307:"307 Temporary Redirect", // retry request elsewhere, don't change 
method.
+  308:"308 Resume Incomplete",
+
+  // Client Error
+  400:"400 Bad Request",
+  401:"401 Access denied",
+  402:"402 Payment Required",
+  403:"403 Forbidden",
+  404:"404 No such file or directory.",
+  405:"405 Method not allowed",
+  406:"406 Not Acceptable",
+  407:"407 Proxy authorization needed",
+  408:"408 Request timeout",
+  409:"409 Conflict",
+  410:"410 Gone",
+  411:"411 Length Required",
+  412:"412 Precondition Failed",
+  413:"413 Request Entity Too Large",
+  414:"414 Request-URI Too Large",
+  415:"415 Unsupported Media Type",
+  416:"416 Requested range not statisfiable",
+  417:"417 Expectation Failed",
+  418:"418 I'm a teapot", // Ha ha
+  422:"422 Unprocessable Entity", // WebDAV
+  423:"423 Locked", // WebDAV
+  424:"424 Failed Dependency", // WebDAV
+  425:"425 Unordered Collection", // RFC3648
+  426:"426 Upgrade Required", // RFC2817
+ + // Internal Server Errors
+  500:"500 Internal Server Error.",
+  501:"501 Not Implemented",
+  502:"502 Bad Gateway",
+  503:"503 Service unavailable",
+  504:"504 Gateway Timeout",
+  505:"505 HTTP Version Not Supported",
+  506:"506 Variant Also Negotiates", // RFC2295
+  507:"507 Insufficient Storage", // WebDAV / RFC4918
+  509:"509 Bandwidth Limit Exceeded", // An Apache defined extension in 
popular use
+  510:"510 Not Extended", // RFC2774
+  598:"598 Network read timeout error", // Informal extension used by some 
HTTP proxies
+  599:"599 Network connect timeout error", // Informal extension used by some 
HTTP proxies
+]);
+
+
 int max_request_size = 0;

 void set_max_request_size(int size)
@@ -475,15 +548,12 @@
            m->error=206;
         }
         break;
-      case 302:
- res+=({protocol+" 302 TEMPORARY REDIRECT"}); - break;
-      case 304:
- res+=({protocol+" 304 Not Modified"}); - break;
       default:
    // better error names?
-        res+=({protocol+" "+m->error+" ERROR"});
+         if(errors[(int)m->error])
+          res+=({protocol+" " + errors[(int)m->error]});
+         else
+          res+=({protocol+" "+m->error+" ERROR"});
         break;
    }

  • [pa... Bill Welliver
    • ... Martin Stjernholm, Roxen IS @ Pike developers forum
      • ... H. William Welliver III
    • ... Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum
      • ... Bill Welliver
        • ... Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum

Reply via email to