]> granicus.if.org Git - php/commitdiff
Revert HTTP status codes merger
authorAndrea Faulds <ajf@ajf.me>
Mon, 15 Dec 2014 01:30:58 +0000 (01:30 +0000)
committerAndrea Faulds <ajf@ajf.me>
Mon, 15 Dec 2014 01:30:58 +0000 (01:30 +0000)
This reverts commits 65768edcf3ef27a21a07e5e994bfd9ca1cabfa94627b350f31be83eb1d5ac5fad692256dcfaf1281 and 9c18ad3ac9103bc0a6c7b7ab8938fd7272095652.

ext/standard/tests/general_functions/header_redirection_001.phpt
ext/standard/tests/general_functions/header_redirection_002.phpt
main/http_status_codes.h [deleted file]
sapi/cgi/cgi_main.c
sapi/cli/php_cli_server.c
sapi/fpm/fpm/fpm_main.c

index c5ea70b56c4c1d01829c84b79d40f068fcb580d4..ecf57ec54a3b56600b4a7fbaac3b12eb1a20b8e1 100644 (file)
@@ -6,6 +6,6 @@ Location: headers change the status code
 header('Location: http://example.com/');
 ?>
 --EXPECTHEADERS--
-Status: 302 Found
+Status: 302 Moved Temporarily
 Location: http://example.com/
 --EXPECT--
index 3f8e0b9dac72137232639c01a5c68e2a36c0c38d..2bf6dec510701908aa56a08348cc8afc0c5398dd 100644 (file)
@@ -7,6 +7,6 @@ header("HTTP/1.1 418 I'm a Teapot");
 header('Location: http://example.com/');
 ?>
 --EXPECTHEADERS--
-Status: 302 Found
+Status: 302 Moved Temporarily
 Location: http://example.com/
 --EXPECT--
diff --git a/main/http_status_codes.h b/main/http_status_codes.h
deleted file mode 100644 (file)
index 02186b5..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
-   +----------------------------------------------------------------------+
-   | PHP Version 7                                                        |
-   +----------------------------------------------------------------------+
-   | Copyright (c) 1997-2014 The PHP Group                                |
-   +----------------------------------------------------------------------+
-   | This source file is subject to version 3.01 of the PHP license,      |
-   | that is bundled with this package in the file LICENSE, and is        |
-   | available through the world-wide-web at the following url:           |
-   | http://www.php.net/license/3_01.txt                                  |
-   | If you did not receive a copy of the PHP license and are unable to   |
-   | obtain it through the world-wide-web, please send a note to          |
-   | license@php.net so we can mail you a copy immediately.               |
-   +----------------------------------------------------------------------+
-   | Author: Andrea Faulds     <ajf@ajf.me>                               |
-   +----------------------------------------------------------------------+
-*/
-
-/* $Id: $ */
-
-#ifndef HTTP_STATUS_CODES_H
-#define HTTP_STATUS_CODES_H
-
-typedef struct _http_response_status_code_pair {
-       int code;
-       const char *str;
-} http_response_status_code_pair;
-
-static http_response_status_code_pair http_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" },
-       /* to allow search with while() loop */
-       { 1000, NULL }
-};
-
-#endif /* HTTP_STATUS_CODES_H */
index 4f97a7014853a2d33600802e189886a88acae92a..1bef17c25743bf5156b66f3047b4d14c5bab74f9 100644 (file)
@@ -69,7 +69,6 @@
 #include "php_globals.h"
 #include "php_main.h"
 #include "fopen_wrappers.h"
-#include "http_status_codes.h"
 #include "ext/standard/php_standard.h"
 #include "ext/standard/url.h"
 
@@ -351,6 +350,56 @@ static void sapi_fcgi_flush(void *server_context TSRMLS_DC)
 
 #define SAPI_CGI_MAX_HEADER_LENGTH 1024
 
+typedef struct _http_error {
+  int code;
+  const char* msg;
+} http_error;
+
+static const http_error http_error_codes[] = {
+       {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, "Moved Temporarily"},
+       {303, "See Other"},
+       {304, "Not Modified"},
+       {305, "Use Proxy"},
+       {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, "Request Entity Too Large"},
+       {414, "Request-URI Too Large"},
+       {415, "Unsupported Media Type"},
+       {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 Time-out"},
+       {505, "HTTP Version not supported"},
+       {511, "Network Authentication Required"},
+       {0,   NULL}
+};
+
 static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
 {
        char buf[SAPI_CGI_MAX_HEADER_LENGTH];
@@ -401,7 +450,7 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
                                        h = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);
                                }
                                if (!has_status) {
-                                       http_response_status_code_pair *err = (http_response_status_code_pair*)http_status_map;
+                                       http_error *err = (http_error*)http_error_codes;
 
                                        while (err->code != 0) {
                                                if (err->code == SG(sapi_headers).http_response_code) {
@@ -409,8 +458,8 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
                                                }
                                                err++;
                                        }
-                                       if (err->str) {
-                                               len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n", SG(sapi_headers).http_response_code, err->str);
+                                       if (err->msg) {
+                                               len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n", SG(sapi_headers).http_response_code, err->msg);
                                        } else {
                                                len = slprintf(buf, sizeof(buf), "Status: %d\r\n", SG(sapi_headers).http_response_code);
                                        }
index 35eab852277777c807fd2994cab365278eb84ef3..a0a9052f8ada5e3d38225ae9bba4cc553b1ea834 100644 (file)
@@ -68,7 +68,6 @@
 #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"
@@ -204,6 +203,55 @@ 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>" },
@@ -276,8 +324,8 @@ static char *get_last_error() /* {{{ */
 
 static int status_comp(const void *a, const void *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;
+       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;
 
        if (pa->code < pb->code) {
                return -1;
@@ -290,12 +338,12 @@ static int status_comp(const void *a, const void *b) /* {{{ */
 
 static const char *get_status_string(int code) /* {{{ */
 {
-       http_response_status_code_pair needle, *result = NULL;
+       php_cli_server_http_response_status_code_pair needle, *result = NULL;
 
        needle.code = code;
        needle.str = NULL;
 
-       result = bsearch(&needle, http_status_map, sizeof(http_status_map) / sizeof(needle), sizeof(needle), status_comp);
+       result = bsearch(&needle, status_map, sizeof(status_map) / sizeof(needle), sizeof(needle), status_comp);
 
        if (result) {
                return result->str;
index d5e5162e7ba8c5053674bdb837d1ec9081ac37fa..2552f9afe0daa110ab8c46c156d3d8284be68af1 100644 (file)
@@ -97,8 +97,6 @@ int __riscosify_control = __RISCOSIFY_STRICT_UNIX_SPECS;
 
 #include "php_getopt.h"
 
-#include "http_status_codes.h"
-
 #include "fastcgi.h"
 
 #include <php_config.h>
@@ -343,6 +341,56 @@ static void sapi_cgibin_flush(void *server_context TSRMLS_DC)
 
 #define SAPI_CGI_MAX_HEADER_LENGTH 1024
 
+typedef struct _http_error {
+       int code;
+       const char* msg;
+} http_error;
+
+static const http_error http_error_codes[] = {
+       {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, "Moved Temporarily"},
+       {303, "See Other"},
+       {304, "Not Modified"},
+       {305, "Use Proxy"},
+       {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, "Request Entity Too Large"},
+       {414, "Request-URI Too Large"},
+       {415, "Unsupported Media Type"},
+       {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 Time-out"},
+       {505, "HTTP Version not supported"},
+       {511, "Network Authentication Required"},
+       {0,   NULL}
+};
+
 static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
 {
        char buf[SAPI_CGI_MAX_HEADER_LENGTH];
@@ -393,7 +441,7 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
                                        h = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);
                                }
                                if (!has_status) {
-                                       http_response_status_code_pair *err = (http_response_status_code_pair*)http_status_map;
+                                       http_error *err = (http_error*)http_error_codes;
 
                                        while (err->code != 0) {
                                                if (err->code == SG(sapi_headers).http_response_code) {
@@ -401,8 +449,8 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
                                                }
                                                err++;
                                        }
-                                       if (err->str) {
-                                               len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n", SG(sapi_headers).http_response_code, err->str);
+                                       if (err->msg) {
+                                               len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n", SG(sapi_headers).http_response_code, err->msg);
                                        } else {
                                                len = slprintf(buf, sizeof(buf), "Status: %d\r\n", SG(sapi_headers).http_response_code);
                                        }