You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-cvs@httpd.apache.org by je...@apache.org on 2002/07/22 07:50:05 UTC
cvs commit: httpd-test/flood CHANGES flood_profile.h flood_socket_keepalive.c
jerenkrantz 2002/07/21 22:50:05
Modified: flood CHANGES flood_profile.h flood_socket_keepalive.c
Log:
Revamp keepalive_recv_resp by utilizing the APR table API to parse the
MIME response headers.
Revision Changes Path
1.39 +5 -0 httpd-test/flood/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/httpd-test/flood/CHANGES,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- CHANGES 11 Jul 2002 18:47:45 -0000 1.38
+++ CHANGES 22 Jul 2002 05:50:05 -0000 1.39
@@ -1,5 +1,10 @@
Changes since milestone-03:
+* Revamp keepalive_recv_resp to use the APR table API. This allows true
+ case insensitivity with the response headers. [Justin Erenkrantz]
+
+* Support autoconf-2.5+. [Justin Erenkrantz]
+
* Switch to new apr_poll() API. [Justin Erenkrantz]
* Stop using the apr_lock.h API and start using apr_thread_mutex.h
1.12 +3 -0 httpd-test/flood/flood_profile.h
Index: flood_profile.h
===================================================================
RCS file: /home/cvs/httpd-test/flood/flood_profile.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- flood_profile.h 31 May 2002 08:01:05 -0000 1.11
+++ flood_profile.h 22 Jul 2002 05:50:05 -0000 1.12
@@ -58,6 +58,7 @@
#define __profile_h
#include <apr_network_io.h> /* Required for apr_socket_t */
+#include <apr_tables.h> /* Required for apr_table_t */
#include <apr_pools.h>
#include <apr_uri.h>
@@ -141,6 +142,8 @@
buffer_type_e rbuftype;
char *rbuf;
apr_size_t rbufsize;
+
+ apr_table_t *headers;
};
typedef struct response_t response_t;
1.15 +40 -20 httpd-test/flood/flood_socket_keepalive.c
Index: flood_socket_keepalive.c
===================================================================
RCS file: /home/cvs/httpd-test/flood/flood_socket_keepalive.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- flood_socket_keepalive.c 31 May 2002 07:59:27 -0000 1.14
+++ flood_socket_keepalive.c 22 Jul 2002 05:50:05 -0000 1.15
@@ -369,10 +369,12 @@
{
keepalive_socket_t *ksock = (keepalive_socket_t *)sock;
char *cl, *ecl, cls[17];
+ char *current_line;
int i;
response_t *new_resp;
apr_status_t status;
long content_length = 0, chunk_length;
+ const char *header;
new_resp = apr_pcalloc(pool, sizeof(response_t));
new_resp->rbuftype = POOL;
@@ -386,28 +388,51 @@
}
/* FIXME: Assume we got the full header for now. */
- /* FIXME: Make case-insensitive */
+ new_resp->headers = apr_table_make(pool, 25);
+ current_line = new_resp->rbuf;
+ do {
+ char *end_of_line, *header_end, *header_key, *header_val;
+ int line_length, key_length;
+
+ end_of_line = strstr(current_line, CRLF);
+ if (!end_of_line || end_of_line == current_line) {
+ break;
+ }
+ line_length = end_of_line - current_line;
+
+ 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);
+ apr_table_set(new_resp->headers, header_key, header_val);
+ }
+ current_line += line_length + sizeof(CRLF) - 1;
+ }
+ while((current_line - new_resp->rbuf) < new_resp->rbufsize);
/* If this exists, we aren't keepalive anymore. */
- cl = strstr(new_resp->rbuf, "Connection: Close" CRLF);
- if (cl) {
+ header = apr_table_get(new_resp->headers, "Connection");
+ if (header && !strcasecmp(header, "Close")) {
new_resp->keepalive = 0;
}
else {
new_resp->keepalive = 1;
}
- cl = strstr(new_resp->rbuf, "Transfer-Encoding: Chunked" CRLF);
- if (cl)
+ header = apr_table_get(new_resp->headers, "Transfer-Encoding");
+ if (header && !strcasecmp(header, "Chunked"))
{
new_resp->chunked = 1;
new_resp->chunk = NULL;
/* Find where headers ended */
- cl = strstr(new_resp->rbuf, CRLF CRLF);
+ cl = current_line;
if (cl) {
/* Skip over the CRLF chars */
- cl += 4;
+ cl += sizeof(CRLF)-1;
}
/* We have a partial chunk and we aren't at the end. */
@@ -456,21 +481,16 @@
}
else
{
- cl = strstr(new_resp->rbuf, "Content-Length: ");
- if (!cl)
+ header = apr_table_get(new_resp->headers, "Content-Length");
+ if (!header)
{
- /* Netscape sends this. It is technically correct as the header
- * may be mixed-case - we should be case-insensitive. But,
- * that gets mighty expensive. */
- cl = strstr(new_resp->rbuf, "Content-length: ");
- if (!cl)
- new_resp->keepalive = 0;
+ new_resp->keepalive = 0;
}
- if (cl)
+ if (header)
{
- cl += sizeof("Content-Length: ") - 1;
- ecl = strstr(cl, CRLF);
+ cl = (char*)header;
+ ecl = cl + strlen(cl);
if (ecl && ecl - cl < 16)
{
strncpy(cls, cl, ecl - cl);
@@ -484,13 +504,13 @@
if (new_resp->keepalive)
{
/* Find where we ended */
- ecl = strstr(new_resp->rbuf, CRLF CRLF);
+ ecl = current_line;
/* We didn't get full headers. Crap. */
if (!ecl)
new_resp->keepalive = 0;
{
- ecl += sizeof(CRLF CRLF) - 1;
+ ecl += sizeof(CRLF) - 1;
content_length -= new_resp->rbufsize - (ecl - (char*)new_resp->rbuf);
}
}