Received: by taz.hyperreal.com (8.7.6/V2.0) id CAA17034; Thu, 10 Oct 1996 02:02:50 -0700 (PDT) Received: by taz.hyperreal.com (8.7.6/V2.0) id CAA17025; Thu, 10 Oct 1996 02:02:48 -0700 (PDT) Date: Thu, 10 Oct 1996 02:02:48 -0700 (PDT) From: Roy Fielding Message-Id: <199610100902.CAA17025@taz.hyperreal.com> To: apache-cvs@hyperreal.com Subject: cvs commit: apache/src httpd.h http_protocol.c Sender: owner-apache-cvs@apache.org Precedence: bulk Reply-To: new-httpd@hyperreal.com fielding 96/10/10 02:02:46 Modified: src httpd.h http_protocol.c Log: Added definitions and status lines for all HTTP/1.1 status codes. Improved the speed of the index_of_response() routine. Reviewed by: Brian Behlendorf, Chuck Murcko Submitted by: Tom Tromey (with major modifications by Roy) Revision Changes Path 1.53 +61 -22 apache/src/httpd.h Index: httpd.h =================================================================== RCS file: /export/home/cvs/apache/src/httpd.h,v retrieving revision 1.52 retrieving revision 1.53 diff -C3 -r1.52 -r1.53 *** httpd.h 1996/10/08 20:43:32 1.52 --- httpd.h 1996/10/10 09:02:43 1.53 *************** *** 50,56 **** * */ ! /* $Id: httpd.h,v 1.52 1996/10/08 20:43:32 brian Exp $ */ /* * httpd.h: header for simple (ha! not anymore) http daemon --- 50,56 ---- * */ ! /* $Id: httpd.h,v 1.53 1996/10/10 09:02:43 fielding Exp $ */ /* * httpd.h: header for simple (ha! not anymore) http daemon *************** *** 251,278 **** #define DECLINED -1 /* Module declines to handle */ #define OK 0 /* Module has handled this stage. */ ! /* ------------------------------ error types ------------------------------ */ ! #define DOCUMENT_FOLLOWS 200 ! #define PARTIAL_CONTENT 206 ! #define MULTIPLE_CHOICES 300 ! #define MOVED 301 ! #define REDIRECT 302 ! #define USE_LOCAL_COPY 304 ! #define BAD_REQUEST 400 ! #define AUTH_REQUIRED 401 ! #define FORBIDDEN 403 ! #define NOT_FOUND 404 ! #define METHOD_NOT_ALLOWED 405 ! #define NOT_ACCEPTABLE 406 ! #define LENGTH_REQUIRED 411 ! #define PRECONDITION_FAILED 412 ! #define SERVER_ERROR 500 ! #define NOT_IMPLEMENTED 501 ! #define BAD_GATEWAY 502 ! #define HTTP_SERVICE_UNAVAILABLE 503 ! #define VARIANT_ALSO_VARIES 506 ! #define RESPONSE_CODES 18 #define METHODS 8 #define M_GET 0 --- 251,317 ---- #define DECLINED -1 /* Module declines to handle */ #define OK 0 /* Module has handled this stage. */ ! /* ----------------------- HTTP Status Codes ------------------------- */ ! #define RESPONSE_CODES 38 ! ! #define HTTP_CONTINUE 100 ! #define HTTP_SWITCHING_PROTOCOLS 101 ! #define HTTP_OK 200 ! #define HTTP_CREATED 201 ! #define HTTP_ACCEPTED 202 ! #define HTTP_NON_AUTHORITATIVE 203 ! #define HTTP_NO_CONTENT 204 ! #define HTTP_RESET_CONTENT 205 ! #define HTTP_PARTIAL_CONTENT 206 ! #define HTTP_MULTIPLE_CHOICES 300 ! #define HTTP_MOVED_PERMANENTLY 301 ! #define HTTP_MOVED_TEMPORARILY 302 ! #define HTTP_SEE_OTHER 303 ! #define HTTP_NOT_MODIFIED 304 ! #define HTTP_USE_PROXY 305 ! #define HTTP_BAD_REQUEST 400 ! #define HTTP_UNAUTHORIZED 401 ! #define HTTP_PAYMENT_REQUIRED 402 ! #define HTTP_FORBIDDEN 403 ! #define HTTP_NOT_FOUND 404 ! #define HTTP_METHOD_NOT_ALLOWED 405 ! #define HTTP_NOT_ACCEPTABLE 406 ! #define HTTP_PROXY_AUTHENTICATION_REQUIRED 407 ! #define HTTP_REQUEST_TIME_OUT 408 ! #define HTTP_CONFLICT 409 ! #define HTTP_GONE 410 ! #define HTTP_LENGTH_REQUIRED 411 ! #define HTTP_PRECONDITION_FAILED 412 ! #define HTTP_REQUEST_ENTITY_TOO_LARGE 413 ! #define HTTP_REQUEST_URI_TOO_LARGE 414 ! #define HTTP_UNSUPPORTED_MEDIA_TYPE 415 ! #define HTTP_INTERNAL_SERVER_ERROR 500 ! #define HTTP_NOT_IMPLEMENTED 501 ! #define HTTP_BAD_GATEWAY 502 ! #define HTTP_SERVICE_UNAVAILABLE 503 ! #define HTTP_GATEWAY_TIME_OUT 504 ! #define HTTP_VERSION_NOT_SUPPORTED 505 ! #define HTTP_VARIANT_ALSO_VARIES 506 ! ! #define DOCUMENT_FOLLOWS HTTP_OK ! #define PARTIAL_CONTENT HTTP_PARTIAL_CONTENT ! #define MULTIPLE_CHOICES HTTP_MULTIPLE_CHOICES ! #define MOVED HTTP_MOVED_PERMANENTLY ! #define REDIRECT HTTP_MOVED_TEMPORARILY ! #define USE_LOCAL_COPY HTTP_NOT_MODIFIED ! #define BAD_REQUEST HTTP_BAD_REQUEST ! #define AUTH_REQUIRED HTTP_UNAUTHORIZED ! #define FORBIDDEN HTTP_FORBIDDEN ! #define NOT_FOUND HTTP_NOT_FOUND ! #define METHOD_NOT_ALLOWED HTTP_METHOD_NOT_ALLOWED ! #define NOT_ACCEPTABLE HTTP_NOT_ACCEPTABLE ! #define LENGTH_REQUIRED HTTP_LENGTH_REQUIRED ! #define PRECONDITION_FAILED HTTP_PRECONDITION_FAILED ! #define SERVER_ERROR HTTP_INTERNAL_SERVER_ERROR ! #define NOT_IMPLEMENTED HTTP_NOT_IMPLEMENTED ! #define BAD_GATEWAY HTTP_BAD_GATEWAY ! #define VARIANT_ALSO_VARIES HTTP_VARIANT_ALSO_VARIES #define METHODS 8 #define M_GET 0 1.54 +62 -51 apache/src/http_protocol.c Index: http_protocol.c =================================================================== RCS file: /export/home/cvs/apache/src/http_protocol.c,v retrieving revision 1.53 retrieving revision 1.54 diff -C3 -r1.53 -r1.54 *** http_protocol.c 1996/10/08 21:46:59 1.53 --- http_protocol.c 1996/10/10 09:02:43 1.54 *************** *** 50,56 **** * */ ! /* $Id: http_protocol.c,v 1.53 1996/10/08 21:46:59 brian Exp $ */ /* * http_protocol.c --- routines which directly communicate with the --- 50,56 ---- * */ ! /* $Id: http_protocol.c,v 1.54 1996/10/10 09:02:43 fielding Exp $ */ /* * http_protocol.c --- routines which directly communicate with the *************** *** 791,863 **** return OK; } ! #define RESPONSE_CODE_LIST " 200 206 300 301 302 304 400 401 403 404 405 406 411 412 500 503 501 502 506" ! ! /* New Apache routine to map error responses into array indicies ! * e.g. 400 -> 0, 500 -> 1, 502 -> 2 ... ! * the indicies have no significance */ ! char *status_lines[] = { "200 OK", "206 Partial Content", "300 Multiple Choices", "301 Moved Permanently", ! "302 Found", "304 Not Modified", "400 Bad Request", ! "401 Unauthorized", "403 Forbidden", ! "404 Not found", "405 Method Not Allowed", "406 Not Acceptable", "411 Length Required", "412 Precondition Failed", ! "500 Server error", ! "503 Out of resources", ! "501 Not Implemented", "502 Bad Gateway", "506 Variant Also Varies" }; ! char *response_titles[] = { ! "200 OK", /* Never actually sent, barring die(200,...) */ ! "206 Partial Content", /* Never sent as an error (we hope) */ ! "Multiple Choices", /* 300 Multiple Choices */ ! "Document moved", /* 301 Redirect */ ! "Document moved", /* 302 Redirect */ ! "304 Not Modified", /* Never sent... 304 MUST be header only */ ! "Bad Request", ! "Authorization Required", ! "Forbidden", ! "File Not found", ! "Method Not Allowed", ! "Not Acceptable", ! "Length Required", ! "Precondition Failed", ! "Server Error", ! "Out of resources", ! "Method not implemented", ! "Bad Gateway", ! "Variant Also Varies" ! }; ! int index_of_response(int err_no) { ! char *cptr, err_string[10]; ! static char *response_codes = RESPONSE_CODE_LIST; ! int index_number; ! ! sprintf(err_string,"%3d",err_no); ! ! cptr = response_codes; ! cptr++; ! index_number = 0; ! while (*cptr && strncmp(cptr, err_string, 3)) { ! cptr += 4; ! index_number++; ! } ! if (!*cptr) return -1; ! return index_number; } --- 791,874 ---- return OK; } ! /* New Apache routine to map status codes into array indicies ! * e.g. 100 -> 0, 101 -> 1, 200 -> 2 ... ! * The number of status lines must equal the value of RESPONSE_CODES (httpd.h) ! * and must be listed in order. */ ! static char *status_lines[] = { ! "100 Continue", ! "101 Switching Protocols", ! #define LEVEL_200 2 "200 OK", + "201 Created", + "202 Accepted", + "203 Non-Authoritative Information", + "204 No Content", + "205 Reset Content", "206 Partial Content", + #define LEVEL_300 9 "300 Multiple Choices", "301 Moved Permanently", ! "302 Moved Temporarily", ! "303 See Other", "304 Not Modified", + "305 Use Proxy", + #define LEVEL_400 15 "400 Bad Request", ! "401 Authorization Required", ! "402 Payment Required", "403 Forbidden", ! "404 File 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 Request Entity Too Large", ! "414 Request-URI Too Large", ! "415 Unsupported Media Type", ! #define LEVEL_500 31 ! "500 Internal Server Error", ! "501 Method Not Implemented", "502 Bad Gateway", + "503 Service Temporarily Unavailable", + "504 Gateway Time-out", + "505 HTTP Version Not Supported", "506 Variant Also Varies" }; ! /* The index is found by its offset from the x00 code of each level. ! * Although this is fast, it will need to be replaced if some nutcase ! * decides to define a high-numbered code before the lower numbers. ! * If that sad event occurs, replace the code below with a linear search ! * from status_lines[shortcut[i]] to status_lines[shortcut[i+1]-1]; ! */ ! int index_of_response(int status) ! { ! static int shortcut[6] = { 0, LEVEL_200, LEVEL_300, LEVEL_400, ! LEVEL_500, RESPONSE_CODES+1 }; ! int i, pos; ! ! if (status < 100) /* Below 100 is illegal for HTTP status */ ! return -1; ! ! for (i = 0; i < 5; i++) { ! status -= 100; ! if (status < 100) { ! pos = (status + shortcut[i]); ! if (pos < shortcut[i+1]) ! return pos; ! else ! return -1; /* status unknown (falls in gap) */ ! } ! } ! return -1; /* 600 or above is also illegal */ } *************** *** 1365,1371 **** r = r->prev; } { ! char *title = response_titles[idx]; BUFF *fd = c->client; bvputs(fd,"", title, "\n

", title, --- 1376,1382 ---- r = r->prev; } { ! char *title = status_lines[idx]; BUFF *fd = c->client; bvputs(fd,"", title, "\n

", title,