The new patch is the first step towards Flood handling "100 continue" 
responses. If such response is found in the first chunk read, and the 
next response is also available there already, then we read past the 100 
message and read in the next message's headers and body if available.

Please evaluate the attached diff file and incorporate into the 
flood_socket_keepalive.c file in CVS. I have made the diff off the build 
1.1 version and not off my own previous changes since this is an 
independent change.

-Norman Tuttle, developer, OpenDemand Systems, [EMAIL PROTECTED]


--- flood_socket_keepalive.c    2003-10-21 13:42:43.000000000 -0400
+++ \flood-1.1\flood_socket_keepalive.c 2003-09-06 00:27:38.000000000 -0400
@@ -241,7 +241,7 @@
                     return status;

                 }

 

-                /* We got caught in the middle of a chunk last time. */

+                /* We got caught in the middle of a chunk last time. */ 

                 if (old_length < 0) {

                     b -= old_length;

                     blen += old_length;

@@ -307,7 +307,7 @@
     return APR_SUCCESS;

 }

 

-static apr_status_t keepalive_load_resp(response_t *resp,

+static apr_status_t keepalive_load_resp(response_t *resp, 

                                         keepalive_socket_t *sock,

                                         apr_size_t remaining, apr_pool_t *pool)

 {

@@ -360,20 +360,12 @@
         cp += i;

         remaining -= i;

     }

-    while (status != APR_EGENERAL && status != APR_EOF &&

+    while (status != APR_EGENERAL && status != APR_EOF && 

            status != APR_TIMEUP && (!remain || remaining));

 

     return status;

 }

 

-enum

-{

-  FIRST_LINE,

-  FIRST_LINE_AFTER_100,

-  AFTER_FIRST_LINE,

-  AFTER_100

-};

-

 /**

  * Keep-alive implementation for recv_resp.

  */

@@ -382,7 +374,6 @@
     keepalive_socket_t *ksock = (keepalive_socket_t *)sock;

     char *cl, *ecl, cls[17];

     char *current_line;

-    int readstate = FIRST_LINE;

     int i;

     response_t *new_resp;

     apr_status_t status;

@@ -408,16 +399,7 @@
         int line_length, key_length;

 

         end_of_line = strstr(current_line, CRLF);

-        if (!end_of_line) break;

-        if (readstate < AFTER_FIRST_LINE) 
readstate=((strncasecmp(current_line, "HTTP/1.1 100", 
12))?AFTER_FIRST_LINE:AFTER_100);

-        if (end_of_line == current_line)

-        {

-            if (readstate == AFTER_100)

-            {

-              current_line += 2; // Add 2 characters to pass the CRLF 
=strlen(CRLF).

-              readstate = FIRST_LINE_AFTER_100;

-              continue;

-            }

+        if (!end_of_line || end_of_line == current_line) {

             break;

         }

         line_length = end_of_line - current_line;

@@ -425,7 +407,7 @@
         header_end = memchr(current_line, ':', line_length);

         if (header_end) {

             key_length = header_end - current_line;

-

+ 

             header_key = apr_pstrmemdup(pool, current_line, key_length);

             header_val = apr_pstrmemdup(pool, current_line + key_length + 2,

                                         line_length - key_length - 2);

@@ -438,10 +420,10 @@
     /* If this exists, we aren't keepalive anymore. */

     header = apr_table_get(new_resp->headers, "Connection");

     if (header && !strcasecmp(header, "Close")) {

-        new_resp->keepalive = 0;

+        new_resp->keepalive = 0; 

     }

     else {

-        new_resp->keepalive = 1;

+        new_resp->keepalive = 1; 

     }

 

     /* If we have a HEAD request, we shouldn't be receiving a body. */

@@ -467,7 +449,7 @@
         /* We have a partial chunk and we aren't at the end. */

         if (cl && *cl && (cl - (char*)new_resp->rbuf) < new_resp->rbufsize) {

             int remaining;

-

+    

             do {

                 if (new_resp->chunk) {

                     /* If we have enough space to skip over the ending CRLF,

@@ -494,8 +476,8 @@
                     foo = strstr(new_resp->chunk, CRLF);

                     assert(foo);

                     new_resp->chunk = foo + 2;

-                    remaining = new_resp->rbufsize -

-                                    (int)(new_resp->chunk -

+                    remaining = new_resp->rbufsize - 

+                                    (int)(new_resp->chunk - 

                                           (char*)new_resp->rbuf);

                 }

                 else {

@@ -513,7 +495,7 @@
         header = apr_table_get(new_resp->headers, "Content-Length");

         if (!header)

         {

-            new_resp->keepalive = 0;

+            new_resp->keepalive = 0; 

         }

 

         if (header)

@@ -526,7 +508,7 @@
                 cls[ecl-cl] = '\0';

                 content_length = strtol(cls, &ecl, 10);

                 if (*ecl != '\0')

-                    new_resp->keepalive = 0;

+                    new_resp->keepalive = 0; 

             }

         }

 

@@ -537,14 +519,14 @@
 

             /* We didn't get full headers.  Crap. */

             if (!ecl)

-                new_resp->keepalive = 0;

+                new_resp->keepalive = 0; 

             {

                 ecl += sizeof(CRLF) - 1;

                 content_length -= new_resp->rbufsize - (ecl - 
(char*)new_resp->rbuf);

-            }

+            } 

         }

     }

-

+   

     if (ksock->wantresponse)

     {

         if (new_resp->keepalive)

@@ -576,7 +558,7 @@
         }

         else

         {

-            while (status != APR_EGENERAL && status != APR_EOF &&

+            while (status != APR_EGENERAL && status != APR_EOF && 

                    status != APR_TIMEUP) {

                 i = MAX_DOC_LENGTH - 1;

                 status = ksock_read_socket(ksock, b, &i);

@@ -600,7 +582,7 @@
         ksock->ssl ? ssl_close_socket(ksock->s) : close_socket(ksock->s);

         ksock->reopen_socket = 1; /* we just closed it */

     }

-

+        

     return APR_SUCCESS;

 }

 

Reply via email to