From: Rasmus Lerdorf Date: Mon, 14 Mar 2005 19:25:39 +0000 (+0000) Subject: Fix for bug #32263 X-Git-Tag: php-5.0.1b1~798 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c0411c496e1b70dd09b094301a4f4a39d8fecab;p=php Fix for bug #32263 This adds proto_num to request_info. It is defaulted to HTTP 1.0 (1000) such that it has a valid value even if the underlying sapi doesn't set it correctly. It is then used to determine if a 302 or a 303 should be sent on a Location redirect. Any non GET/HEAD HTTP 1.1 redirect will get a 303 instead of a 302 to be compatible with the HTTP spec. --- diff --git a/main/SAPI.c b/main/SAPI.c index c0c95ae95e..5ff76c35b2 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -346,6 +346,7 @@ SAPI_API void sapi_activate(TSRMLS_D) SG(request_info).current_user_length = 0; SG(request_info).no_headers = 0; SG(request_info).post_entry = NULL; + SG(request_info).proto_num = 1000; /* Default to HTTP 1.0 */ SG(global_request_time) = 0; /* It's possible to override this general case in the activate() callback, if @@ -608,7 +609,14 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC) SG(sapi_headers).http_response_code > 307) && SG(sapi_headers).http_response_code != 201) { /* Return a Found Redirect if one is not already specified */ - sapi_update_response_code(302 TSRMLS_CC); + if(SG(request_info).proto_num > 1000 && + SG(request_info).request_method && + strcmp(SG(request_info).request_method, "HEAD") && + strcmp(SG(request_info).request_method, "GET")) { + sapi_update_response_code(303 TSRMLS_CC); + } else { + sapi_update_response_code(302 TSRMLS_CC); + } } } else if (!STRCASECMP(header_line, "WWW-Authenticate")) { /* HTTP Authentication */ diff --git a/main/SAPI.h b/main/SAPI.h index ca6836a0cb..9ef7eecbdb 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -109,6 +109,7 @@ typedef struct { /* this is necessary for CLI module */ int argc; char **argv; + int proto_num; } sapi_request_info; diff --git a/sapi/aolserver/aolserver.c b/sapi/aolserver/aolserver.c index 7109e11a51..1aa460358b 100644 --- a/sapi/aolserver/aolserver.c +++ b/sapi/aolserver/aolserver.c @@ -444,6 +444,8 @@ php_ns_request_ctor(TSRMLS_D) root = Ns_PageRoot(server); SG(request_info).request_uri = strdup(SG(request_info).path_translated + strlen(root)); SG(request_info).request_method = NSG(conn)->request->method; + if(NSG(conn)->request->version > 1.0) SG(request_info).proto_num = 1001; + else SG(request_info).proto_num = 1000; SG(request_info).content_length = Ns_ConnContentLength(NSG(conn)); index = Ns_SetIFind(NSG(conn)->headers, "content-type"); SG(request_info).content_type = index == -1 ? NULL : diff --git a/sapi/apache/mod_php5.c b/sapi/apache/mod_php5.c index ad2f3b3520..59be19df4b 100644 --- a/sapi/apache/mod_php5.c +++ b/sapi/apache/mod_php5.c @@ -484,6 +484,7 @@ static void init_request_info(TSRMLS_D) SG(request_info).content_type = (char *) table_get(r->subprocess_env, "CONTENT_TYPE"); SG(request_info).content_length = (content_length ? atoi(content_length) : 0); SG(sapi_headers).http_response_code = r->status; + SG(request_info).proto_num = r->proto_num; if (r->headers_in) { authorization = table_get(r->headers_in, "Authorization"); diff --git a/sapi/apache2filter/sapi_apache2.c b/sapi/apache2filter/sapi_apache2.c index 11713ef75c..359c3442c8 100644 --- a/sapi/apache2filter/sapi_apache2.c +++ b/sapi/apache2filter/sapi_apache2.c @@ -397,6 +397,7 @@ static void php_apache_request_ctor(ap_filter_t *f, php_struct *ctx TSRMLS_DC) #define safe_strdup(x) ((x)?strdup((x)):NULL) SG(request_info).query_string = safe_strdup(f->r->args); SG(request_info).request_method = f->r->method; + SG(request_info).proto_num = f->r->proto_num; SG(request_info).request_uri = safe_strdup(f->r->uri); SG(request_info).path_translated = safe_strdup(f->r->filename); f->r->no_local_copy = 1; diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c index 39c17bc111..1d7e33fbb0 100644 --- a/sapi/apache2handler/sapi_apache2.c +++ b/sapi/apache2handler/sapi_apache2.c @@ -418,6 +418,7 @@ static int php_apache_request_ctor(request_rec *r, php_struct *ctx TSRMLS_DC) SG(request_info).content_type = apr_table_get(r->headers_in, "Content-Type"); SG(request_info).query_string = apr_pstrdup(r->pool, r->args); SG(request_info).request_method = r->method; + SG(request_info).proto_num = r->proto_num; SG(request_info).request_uri = apr_pstrdup(r->pool, r->uri); SG(request_info).path_translated = apr_pstrdup(r->pool, r->filename); r->no_local_copy = 1; diff --git a/sapi/apache_hooks/mod_php5.c b/sapi/apache_hooks/mod_php5.c index 4eead831c6..aafed496cd 100644 --- a/sapi/apache_hooks/mod_php5.c +++ b/sapi/apache_hooks/mod_php5.c @@ -571,6 +571,7 @@ static void init_request_info(TSRMLS_D) SG(request_info).path_translated = r->filename; SG(request_info).request_uri = r->uri; SG(request_info).request_method = (char *)r->method; + SG(request_info).proto_num = r->proto_num; SG(request_info).content_type = (char *) table_get(r->subprocess_env, "CONTENT_TYPE"); SG(request_info).content_length = (content_length ? atoi(content_length) : 0); SG(sapi_headers).http_response_code = r->status; diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 572db4078c..9cc8d220a5 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -676,6 +676,7 @@ static void init_request_info(TSRMLS_D) /* initialize the defaults */ SG(request_info).path_translated = NULL; SG(request_info).request_method = NULL; + SG(request_info).proto_num = 1000; SG(request_info).query_string = NULL; SG(request_info).request_uri = NULL; SG(request_info).content_type = NULL; @@ -862,6 +863,7 @@ static void init_request_info(TSRMLS_D) } #endif SG(request_info).request_method = sapi_cgibin_getenv("REQUEST_METHOD",0 TSRMLS_CC); + /* FIXME - Work out proto_num here */ SG(request_info).query_string = sapi_cgibin_getenv("QUERY_STRING",0 TSRMLS_CC); /* some server configurations allow '..' to slip through in the translated path. We'll just refuse to handle such a path. */ diff --git a/sapi/thttpd/thttpd.c b/sapi/thttpd/thttpd.c index 16dcb09553..1bd532bbe2 100644 --- a/sapi/thttpd/thttpd.c +++ b/sapi/thttpd/thttpd.c @@ -451,6 +451,8 @@ static void thttpd_request_ctor(TSRMLS_D) smart_str_0(&s); SG(request_info).request_uri = s.c; SG(request_info).request_method = httpd_method_str(TG(hc)->method); + if (TG(hc)->one_one) SG(request_info).proto_num = 1001; + else SG(request_info).proto_num = 1000; SG(sapi_headers).http_response_code = 200; if (TG(hc)->contenttype) SG(request_info).content_type = strdup(TG(hc)->contenttype); diff --git a/sapi/tux/php_tux.c b/sapi/tux/php_tux.c index e7cbf217cd..d227b65172 100644 --- a/sapi/tux/php_tux.c +++ b/sapi/tux/php_tux.c @@ -336,6 +336,8 @@ static void tux_request_ctor(TSRMLS_D) smart_str_0(&s); SG(request_info).request_uri = s.c; SG(request_info).request_method = CGI_REQUEST_METHOD(TG(req)); + if(TG(req)->http_version == HTTP_1_1) SG(request_info).proto_num = 1001; + else SG(request_info).proto_num = 1000; SG(sapi_headers).http_response_code = 200; SG(request_info).content_type = TG(req)->content_type; SG(request_info).content_length = 0; /* TG(req)->contentlength; */