]> granicus.if.org Git - php/commitdiff
Heads up! I have moved the headers_only and response_code checks out of
authorRasmus Lerdorf <rasmus@php.net>
Wed, 2 Aug 2000 22:48:45 +0000 (22:48 +0000)
committerRasmus Lerdorf <rasmus@php.net>
Wed, 2 Aug 2000 22:48:45 +0000 (22:48 +0000)
SAPI and down into the individual SAPI modules.  I have made the
appropriate changes in all the SAPI modules, but please verify these.
The reason for this change is that Apache sometimes will feed PHP
a request_method of GET but have r->header_only set to true.  This happens
in an ErrorDocument redirect.  In this same scenario we want to preserve
the status code as well instead of just overwriting it with a 200 and
losing this information.  For now the other sapi modules act exactly as
before since they probably do not make this distinction, and they may
not even have a valid response code this early in the request.
@ Fix HEAD request bug on an Apache ErrorDocument redirect and preserve
@ the status code across the redirect as well.  (Rasmus)

main/SAPI.c
sapi/aolserver/aolserver.c
sapi/apache/mod_php4.c
sapi/cgi/cgi_main.c
sapi/isapi/php4isapi.c
sapi/nsapi/nsapi.c
sapi/phttpd/phttpd.c
sapi/pi3web/pi3web_sapi.c
sapi/roxen/roxen.c
sapi/servlet/servlet.c
sapi/thttpd/thttpd.c

index ae89815a82ae5b0a76c0ea09b615c33950d68bdf..c3e1bb720e778ccda44e937ed6df473bcd35f5d0 100644 (file)
@@ -267,19 +267,27 @@ SAPI_API void sapi_activate(SLS_D)
        zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct), (void (*)(void *)) sapi_free_header, 0);
        SG(sapi_headers).send_default_content_type = 1;
 
+       /*
        SG(sapi_headers).http_response_code = 200;
        SG(sapi_headers).http_status_line = NULL;
+       */
        SG(headers_sent) = 0;
        SG(read_post_bytes) = 0;
        SG(request_info).post_data = NULL;
        SG(request_info).current_user = NULL;
        SG(request_info).current_user_length = 0;
 
+#if 0
+       /* This can't be done here.  We need to do that in the individual SAPI
+        * modules because you can actually have a GET request that is only
+        * allowed to send back headers. 
+        */
        if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) {
                SG(request_info).headers_only = 1;
        } else {
                SG(request_info).headers_only = 0;
        }
+#endif
 
        if (SG(server_context)) {
                if (SG(request_info).request_method 
index 21c4b4ff2ef6cee2fcae3b37b7faa94b03d91a71..67ca6d59929e77a70ba5d257530371b237125234 100644 (file)
@@ -473,6 +473,12 @@ php_ns_request_ctor(NSLS_D SLS_DC)
        index = Ns_SetIFind(NSG(conn)->headers, "content-type");
        SG(request_info).content_type = index == -1 ? NULL : 
                Ns_SetValue(NSG(conn)->headers, index);
+       if (!strcmp(NSG(conn)->request->method, "HEAD")) {
+               SG(request_info).headers_only = 1;
+       } else {
+               SG(request_info).headers_only = 0;
+       }
+       SG(sapi_headers).http_response_code = 200;
 
        tmp = Ns_ConnAuthUser(NSG(conn));
        if(tmp) {
index c5a51e8092ea00e051450b388aef0368d70770e5..c3b81390ea1a9ae3d3c61787422a8fe6a6c3c405 100644 (file)
@@ -379,6 +379,8 @@ static void init_request_info(SLS_D)
        SG(request_info).request_method = (char *)r->method;
        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(request_info).headers_only = r->header_only;
+       SG(sapi_headers).http_response_code = r->status;
 
        if (r->headers_in) {
                authorization = table_get(r->headers_in, "Authorization");
index d61bea902fcbbee908c293ceabf4a8126479c191..10d5d39059e7bd33681c51bcacfd95a4258bcc1b 100644 (file)
@@ -315,7 +315,12 @@ static void init_request_info(SLS_D)
        SG(request_info).path_translated = NULL; /* we have to update it later, when we have that information */
        SG(request_info).content_type = getenv("CONTENT_TYPE");
        SG(request_info).content_length = (content_length?atoi(content_length):0);
-
+       SG(sapi_headers).http_response_code = 200;
+       if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) {
+               SG(request_info).headers_only = 1;
+       } else {
+               SG(request_info).headers_only = 0;
+       }
        /* CGI does not support HTTP authentication */
        SG(request_info).auth_user = NULL;
        SG(request_info).auth_password = NULL;
index 949e96bc0091f51a02f12f3b75c9394a60af51a6..5e48b35811ca03a1adfc2b578e9f2e890125bf73 100644 (file)
@@ -463,6 +463,12 @@ static void init_request_info(sapi_globals_struct *sapi_globals, LPEXTENSION_CON
        SG(request_info).request_uri = lpECB->lpszPathInfo;
        SG(request_info).content_type = lpECB->lpszContentType;
        SG(request_info).content_length = lpECB->cbTotalBytes;
+       SG(sapi_headers).http_response_code = 200;  /* I think dwHttpStatusCode is invalid at this stage -RL */
+       if (!strcmp(lpECB->lpszMethod, "HEAD")) {
+               SG(request_info).headers_only = 1;
+       } else {
+               SG(request_info).headers_only = 0;
+       }
        {
                char *path_end = strrchr(SG(request_info).path_translated, SEPARATOR);
 
index 4e664b6559c72ca62a568d5cae5ca1f38776c11a..94ac4072f77042d9bb1cbc81c9b9cc5a0299a2bb 100644 (file)
@@ -478,6 +478,13 @@ nsapi_request_ctor(NSLS_D SLS_DC)
        SG(request_info).path_translated = nsapi_strdup(path_translated);
        SG(request_info).content_type = nsapi_strdup(content_type);
        SG(request_info).content_length = (content_length == NULL) ? 0 : strtoul(content_length, 0, 0);
+       SG(sapi_headers).http_response_code = 200;
+       if (!strcmp(request_method, "HEAD")) {
+               SG(request_info).headers_only = 1;
+       } else {
+               SG(request_info).headers_only = 0;
+       }
+
 }
 
 static void
index 9f2eda9c1661ed8624dfe8ef859e148bf4f60553..72d81f401af5823d952619e6dcf3f3cb4575ef34 100644 (file)
@@ -202,6 +202,12 @@ php_phttpd_request_ctor(PHLS_D SLS_DC)
     SG(request_info).query_string = PHG(cip)->hip->request;
     SG(request_info).request_method = PHG(cip)->hip->method;
        SG(request_info).path_translated = malloc(MAXPATHLEN+1);
+    SG(sapi_headers).http_response_code = 200;
+       if (!strcmp(PHG(cip)->hip->method, "HEAD")) {
+               SG(request_info).headers_only = 1;
+       } else {
+               SG(request_info).headers_only = 0;
+       }
        if (url_expand(PHG(cip)->hip->url, SG(request_info).path_translated, MAXPATHLEN, &PHG(sb), NULL, NULL) == NULL) {
                /* handle error */
        }
index c6a6f839b0cd956e5b1485a2da07b159a7958645..ff2951e708f2d7e27912f3f837d018405ba92072 100644 (file)
@@ -321,6 +321,12 @@ static void init_request_info(sapi_globals_struct *sapi_globals, LPCONTROL_BLOCK
        SG(request_info).content_length  = lpCB->cbTotalBytes;
        SG(request_info).auth_user       = lpCB->lpszUser;
        SG(request_info).auth_password   = lpCB->lpszPassword;
+       SG(sapi_headers).http_response_code = 200;
+       if (!strcmp(lpCB->lpszMethod, "HEAD")) {
+               SG(request_info).headers_only = 1;
+       } else {
+               SG(request_info).headers_only = 0;
+       }
 }
 
 static void hash_pi3web_variables(ELS_D SLS_DC)
index 82c93664bb37eb02bb43d2cf3de601789c505d0f..740104da91b9141bf7bcc00cbcfa313b16c9ce08 100644 (file)
@@ -671,7 +671,13 @@ void f_php_roxen_request_handler(INT32 args)
   SG(request_info).request_method = lookup_string_header("REQUEST_METHOD", "GET");
   SG(request_info).content_length = lookup_integer_header("HTTP_CONTENT_LENGTH", 0);
   SG(request_info).content_type = lookup_string_header("HTTP_CONTENT_TYPE", NULL);
-  
+  SG(sapi_headers).http_response_code = 200;
+  if (!strcmp(SG(request_info).request_method, "HEAD")) {
+    SG(request_info).headers_only = 1;
+  } else {
+    SG(request_info).headers_only = 0;
+  }
+
   /* FIXME: Check for auth stuff needs to be fixed... */ 
   SG(request_info).auth_user = NULL; 
   SG(request_info).auth_password = NULL;
index 3f5c7d19ffc7bc050334c1e05da56e530d19fc28..2661d8fabed36ed9bcc559771c1310d8ce865a2a 100644 (file)
@@ -356,6 +356,12 @@ JNIEXPORT void JNICALL Java_net_php_servlet_send
        SETSTRING( SG(request_info).query_string, queryString );
        SETSTRING( SG(request_info).request_uri, requestURI );
        SETSTRING( SG(request_info).content_type, contentType );
+       SG(sapi_headers).http_response_code = 200;
+       if (!strcmp(SG(request_info).request_method, "HEAD")) {
+               SG(request_info).headers_only = 1;
+       } else {
+               SG(request_info).headers_only = 1;
+       }
        SG(request_info).content_length = contentLength;
        SG(request_info).auth_password = NULL;
        if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) {
index a9fe305b03b404fc383b6cdc1f4dfb394fb42e36..daef768dfc48e00adba288cad48912ece7928282 100644 (file)
@@ -245,7 +245,12 @@ static void thttpd_request_ctor(TLS_D SLS_DC)
        snprintf(buf, 1023, "/%s", TG(hc)->origfilename);
        SG(request_info).request_uri = strdup(buf);
        SG(request_info).request_method = httpd_method_str(TG(hc)->method);
-
+       if (!strcmp(SG(request_info).request_method, "HEAD")) {
+               SG(request_info).headers_only = 1;
+       } else {
+               SG(request_info).headers_only = 0;
+       }
+       SG(sapi_headers).http_response_code = 200;
        SG(request_info).content_type = TG(hc)->contenttype;
        SG(request_info).content_length = TG(hc)->contentlength;