Unify HTTP status code maps

This commit is contained in:
Andrea Faulds 2014-12-15 02:26:00 +00:00
parent dca2e96885
commit e20cbdbe97
6 changed files with 99 additions and 164 deletions

View file

@ -68,6 +68,7 @@
#include "zend_hash.h"
#include "zend_modules.h"
#include "fopen_wrappers.h"
#include "http_status_codes.h"
#include "zend_compile.h"
#include "zend_execute.h"
@ -203,55 +204,6 @@ typedef struct php_cli_server_http_response_status_code_pair {
const char *str;
} php_cli_server_http_response_status_code_pair;
static php_cli_server_http_response_status_code_pair status_map[] = {
{ 100, "Continue" },
{ 101, "Switching Protocols" },
{ 200, "OK" },
{ 201, "Created" },
{ 202, "Accepted" },
{ 203, "Non-Authoritative Information" },
{ 204, "No Content" },
{ 205, "Reset Content" },
{ 206, "Partial Content" },
{ 300, "Multiple Choices" },
{ 301, "Moved Permanently" },
{ 302, "Found" },
{ 303, "See Other" },
{ 304, "Not Modified" },
{ 305, "Use 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 Timeout" },
{ 409, "Conflict" },
{ 410, "Gone" },
{ 411, "Length Required" },
{ 412, "Precondition Failed" },
{ 413, "Request Entity Too Large" },
{ 414, "Request-URI Too Long" },
{ 415, "Unsupported Media Type" },
{ 416, "Requested Range Not Satisfiable" },
{ 417, "Expectation Failed" },
{ 426, "Upgrade Required" },
{ 428, "Precondition Required" },
{ 429, "Too Many Requests" },
{ 431, "Request Header Fields Too Large" },
{ 500, "Internal Server Error" },
{ 501, "Not Implemented" },
{ 502, "Bad Gateway" },
{ 503, "Service Unavailable" },
{ 504, "Gateway Timeout" },
{ 505, "HTTP Version Not Supported" },
{ 511, "Network Authentication Required" },
};
static php_cli_server_http_response_status_code_pair template_map[] = {
{ 400, "<h1>%s</h1><p>Your browser sent a request that this server could not understand.</p>" },
{ 404, "<h1>%s</h1><p>The requested resource <code class=\"url\">%s</code> was not found on this server.</p>" },
@ -324,8 +276,8 @@ static char *get_last_error() /* {{{ */
static int status_comp(const void *a, const void *b) /* {{{ */
{
const php_cli_server_http_response_status_code_pair *pa = (const php_cli_server_http_response_status_code_pair *) a;
const php_cli_server_http_response_status_code_pair *pb = (const php_cli_server_http_response_status_code_pair *) b;
const http_response_status_code_pair *pa = (const http_response_status_code_pair *) a;
const http_response_status_code_pair *pb = (const http_response_status_code_pair *) b;
if (pa->code < pb->code) {
return -1;
@ -338,12 +290,10 @@ static int status_comp(const void *a, const void *b) /* {{{ */
static const char *get_status_string(int code) /* {{{ */
{
php_cli_server_http_response_status_code_pair needle, *result = NULL;
http_response_status_code_pair needle = {code, NULL},
*result = NULL;
needle.code = code;
needle.str = NULL;
result = bsearch(&needle, status_map, sizeof(status_map) / sizeof(needle), sizeof(needle), status_comp);
result = bsearch(&needle, http_status_map, http_status_map_len, sizeof(needle), status_comp);
if (result) {
return result->str;