]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Make ap_set_keepalive more statefully aware, allowing it
authorJim Jagielski <jim@apache.org>
Fri, 27 Aug 2004 23:44:41 +0000 (23:44 +0000)
committerJim Jagielski <jim@apache.org>
Fri, 27 Aug 2004 23:44:41 +0000 (23:44 +0000)
to be called multiple times (to correctly set keepalive)
but not increment keepalives when not needed. This allows
us to handle a special case where we need to discard
body content "early"

PR:
Obtained from:
Submitted by:
Reviewed by:

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x@104871 13f79535-47bb-0310-9956-ffa450edef68

src/CHANGES
src/main/http_protocol.c
src/main/http_request.c

index 702264d01dde095d0bc1d8e168cbabc245ca0535..de864cdc857464657a8740beb8ef5fc0ba78b570 100644 (file)
@@ -24,9 +24,10 @@ Changes with Apache 1.3.32
      was not checked properly. This affects mod_usertrack and
      core. PR 28218.  [AndrĂ© Malo]
 
-  *) No longer breaks mod_dav, frontpage and others.  Backs out
-     a patch which prevented discarding the request body for requests
+  *) No longer breaks mod_dav, frontpage and others.  Repair a patch
+     in 1.3.31 which prevented discarding the request body for requests
      that will be keptalive but are not currently keptalive. PR 29237.
+     [Jim Jagielski]
 
   *) COMPATIBILITY: Added new compile-time flag: UCN_OFF_HONOR_PHYSICAL_PORT.
      It controls how UseCanonicalName Off determines the port value if
index a1dab39b767d9386ff206c0d204e0cdb130517d1..8211a4466051fd7c1f061d196f1a828b14388d19 100644 (file)
@@ -391,6 +391,7 @@ API_EXPORT(int) ap_set_keepalive(request_rec *r)
     int wimpy = ap_find_token(r->pool,
                            ap_table_get(r->headers_out, "Connection"), "close");
     const char *conn = ap_table_get(r->headers_in, "Connection");
+    const char *herebefore = ap_table_get(r->notes, "ap_set_keepalive-called");
 
     /* The following convoluted conditional determines whether or not
      * the current connection should remain persistent after this response
@@ -442,7 +443,17 @@ API_EXPORT(int) ap_set_keepalive(request_rec *r)
         int left = r->server->keep_alive_max - r->connection->keepalives;
 
         r->connection->keepalive = 1;
-        r->connection->keepalives++;
+       /*
+        * ap_set_keepalive could be called multiple times (eg: in
+        * ap_die() followed by ap_send_http_header()) during this
+        * one single request. To ensure that we don't incorrectly
+        * increment the keepalives counter for each call, we
+        * use notes to store a state flag.
+        */
+       if (!herebefore) {
+            r->connection->keepalives++;
+            ap_table_setn(r->notes, "ap_set_keepalive-called", "1");
+       }
 
         /* If they sent a Keep-Alive token, send one back */
         if (ka_sent) {
index ef4ed74a7e68c2054725240664634b453a39d310..64f5914800defcebe8dca788341263743934c4ef 100644 (file)
@@ -1050,13 +1050,19 @@ API_EXPORT(void) ap_die(int type, request_rec *r)
         r->status = HTTP_PROXY_AUTHENTICATION_REQUIRED;
     }
 
+    /*
+     * We need to ensure that r->connection->keepalive is valid in
+     * order to determine if we can discard the request body below.
+     */
+    ap_set_keepalive(r);
+
     /*
      * If we want to keep the connection, be sure that the request body
      * (if any) has been read.
      */
     if ((r->status != HTTP_NOT_MODIFIED) && (r->status != HTTP_NO_CONTENT)
         && !ap_status_drops_connection(r->status)
-        && r->connection && (r->connection->keepalive != -1)) {
+        && r->connection && (r->connection->keepalive > 0)) {
 
         (void) ap_discard_request_body(r);
     }