dmitry Thu Nov 1 11:12:34 2007 UTC
Modified files: (Branch: PHP_5_3)
/php-src NEWS
/php-src/sapi/cgi cgi_main.c
Log:
Fixed bug #42848 (Status: header incorrect under FastCGI)
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.34&r2=1.2027.2.547.2.965.2.35&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.34
php-src/NEWS:1.2027.2.547.2.965.2.35
--- php-src/NEWS:1.2027.2.547.2.965.2.34 Mon Oct 29 17:17:54 2007
+++ php-src/NEWS Thu Nov 1 11:12:33 2007
@@ -45,6 +45,7 @@
- Fixed possible crash in ext/soap because of uninitialized value (Zdash Urf)
+- Fixed bug #42848 (Status: header incorrect under FastCGI). (Dmitry)
- Fixed bug #42737 (preg_split('//u') triggers a E_NOTICE with newlines).
(Nuno)
- Fixed bug #42657 (ini_get() returns incorrect value when default is NULL).
(Jani)
http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.267.2.15.2.50.2.7&r2=1.267.2.15.2.50.2.8&diff_format=u
Index: php-src/sapi/cgi/cgi_main.c
diff -u php-src/sapi/cgi/cgi_main.c:1.267.2.15.2.50.2.7
php-src/sapi/cgi/cgi_main.c:1.267.2.15.2.50.2.8
--- php-src/sapi/cgi/cgi_main.c:1.267.2.15.2.50.2.7 Fri Oct 26 04:46:12 2007
+++ php-src/sapi/cgi/cgi_main.c Thu Nov 1 11:12:33 2007
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: cgi_main.c,v 1.267.2.15.2.50.2.7 2007/10/26 04:46:12 dmitry Exp $ */
+/* $Id: cgi_main.c,v 1.267.2.15.2.50.2.8 2007/11/01 11:12:33 dmitry Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -318,6 +318,52 @@
#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"},
+ {500, "Internal Server Error"},
+ {501, "Not Implemented"},
+ {502, "Bad Gateway"},
+ {503, "Service Unavailable"},
+ {504, "Gateway Time-out"},
+ {505, "HTTP Version not supported"},
+ {0, NULL}
+};
+
static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
{
char buf[SAPI_CGI_MAX_HEADER_LENGTH];
@@ -331,6 +377,7 @@
if (CGIG(nph) || SG(sapi_headers).http_response_code != 200)
{
int len;
+ zend_bool has_status = 0;
if (CGIG(rfc2616_headers) && SG(sapi_headers).http_status_line)
{
len = slprintf(buf, SAPI_CGI_MAX_HEADER_LENGTH,
"%s\r\n", SG(sapi_headers).http_status_line);
@@ -349,11 +396,35 @@
) {
len = slprintf(buf, sizeof(buf),
"Status:%s\r\n", s);
} else {
- len = slprintf(buf, sizeof(buf), "Status:
%d\r\n", SG(sapi_headers).http_response_code);
+ h =
(sapi_header_struct*)zend_llist_get_first_ex(&sapi_headers->headers, &pos);
+ while (h) {
+ if (h->header_len > sizeof("Status:")-1
&&
+ strncasecmp(h->header, "Status:",
sizeof("Status:")-1) == 0) {
+ has_status = 1;
+ break;
+ }
+ h =
(sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);
+ }
+ if (!has_status) {
+ http_error *err =
(http_error*)http_error_codes;
+
+ while (err->code != 0) {
+ if (err->code ==
SG(sapi_headers).http_response_code) {
+ break;
+ }
+ err++;
+ }
+ 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);
+ }
+ }
}
}
-
- PHPWRITE_H(buf, len);
+ if (!has_status) {
+ PHPWRITE_H(buf, len);
+ }
}
h =
(sapi_header_struct*)zend_llist_get_first_ex(&sapi_headers->headers, &pos);
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php