mirror of
https://github.com/php/php-src.git
synced 2025-08-18 06:58:55 +02:00
Unify HTTP status code maps
This commit is contained in:
parent
dca2e96885
commit
e20cbdbe97
6 changed files with 99 additions and 164 deletions
|
@ -69,6 +69,7 @@
|
|||
#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"
|
||||
|
||||
|
@ -353,56 +354,6 @@ static void sapi_fcgi_flush(void *server_context)
|
|||
|
||||
#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)
|
||||
{
|
||||
char buf[SAPI_CGI_MAX_HEADER_LENGTH];
|
||||
|
@ -453,7 +404,7 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers)
|
|||
h = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);
|
||||
}
|
||||
if (!has_status) {
|
||||
http_error *err = (http_error*)http_error_codes;
|
||||
http_response_status_code_pair *err = (http_response_status_code_pair*)http_status_map;
|
||||
|
||||
while (err->code != 0) {
|
||||
if (err->code == SG(sapi_headers).http_response_code) {
|
||||
|
@ -461,8 +412,8 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers)
|
|||
}
|
||||
err++;
|
||||
}
|
||||
if (err->msg) {
|
||||
len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n", SG(sapi_headers).http_response_code, err->msg);
|
||||
if (err->str) {
|
||||
len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n", SG(sapi_headers).http_response_code, err->str);
|
||||
} else {
|
||||
len = slprintf(buf, sizeof(buf), "Status: %d\r\n", SG(sapi_headers).http_response_code);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue