]> granicus.if.org Git - php/commitdiff
Fix for bug #32263
authorRasmus Lerdorf <rasmus@php.net>
Mon, 14 Mar 2005 19:25:39 +0000 (19:25 +0000)
committerRasmus Lerdorf <rasmus@php.net>
Mon, 14 Mar 2005 19:25:39 +0000 (19:25 +0000)
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.

main/SAPI.c
main/SAPI.h
sapi/aolserver/aolserver.c
sapi/apache/mod_php5.c
sapi/apache2filter/sapi_apache2.c
sapi/apache2handler/sapi_apache2.c
sapi/apache_hooks/mod_php5.c
sapi/cgi/cgi_main.c
sapi/thttpd/thttpd.c
sapi/tux/php_tux.c

index c0c95ae95ee2b717bd8bbd99b2998d998f0028fc..5ff76c35b29aa6344d7c28231bf3d090e6299bf2 100644 (file)
@@ -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 */
 
index ca6836a0cb472befc0789db02b20ba3c0c706e3a..9ef7eecbdb39cb2a8b7448845455c3c81549fbb1 100644 (file)
@@ -109,6 +109,7 @@ typedef struct {
     /* this is necessary for CLI module */
     int argc;
     char **argv;
+       int proto_num;
 } sapi_request_info;
 
 
index 7109e11a5152de74f29a2fcc1322aa82b70f8aab..1aa460358b613f252e1f2358109ababec056d69f 100644 (file)
@@ -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 : 
index ad2f3b35209addf950ab6c44ffdf9d10f17b09da..59be19df4bac0115c7ac02915e7f8bec68c8af2a 100644 (file)
@@ -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");
index 11713ef75c8a655f074de0c9bc9d8b94015929e3..359c3442c8c4649b4a62236f158f806a750edf7e 100644 (file)
@@ -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;
index 39c17bc111612e7d590ca8d7b387778fd9dbbc67..1d7e33fbb0821678676d0b621e7d43a383b73342 100644 (file)
@@ -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;
index 4eead831c6d865296657e3f59953709991736fb5..aafed496cd9f9e210985181830402fb6d4974199 100644 (file)
@@ -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;
index 572db4078c552efedd07fea469e5eb92ab5f498a..9cc8d220a50bf6b8b88c817e087c8e770b685e23 100644 (file)
@@ -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. */
index 16dcb09553ed2cd7e01669cdd30f387bbfa30662..1bd532bbe23418d6bd1763bcfc421fc07c6480b5 100644 (file)
@@ -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);
index e7cbf217cd02c569119bef943d547ee8757d1ab2..d227b651721fa2e44ce268917c86268c6a4e7ff2 100644 (file)
@@ -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; */