]> granicus.if.org Git - apache/commitdiff
Remove the lameo create_req hack and delay the addition of the HTTP_IN
authorJustin Erenkrantz <jerenkrantz@apache.org>
Sat, 29 Sep 2001 08:48:59 +0000 (08:48 +0000)
committerJustin Erenkrantz <jerenkrantz@apache.org>
Sat, 29 Sep 2001 08:48:59 +0000 (08:48 +0000)
filter until after we have read the headers.  This eliminates the status
hack that was in http_protocol.c and makes it all around better.

server/protocol.c now directly adds HTTP_IN filter - should we create a
specific hook for this?  (Could we do this as a post_read_request hook?)
I'm not terribly sure, but let's move it down to the lowest possible
place in ap_read_request.  We can change this detail later as we see fit.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@91192 13f79535-47bb-0310-9956-ffa450edef68

modules/http/http_core.c
modules/http/http_protocol.c
server/protocol.c

index fc51a1558c4b639ed6fac947c79da12ffb7f9c17..be64ced5eb338eefaf27a49ec6f78d8bd6958617 100644 (file)
@@ -301,15 +301,6 @@ static int ap_process_http_connection(conn_rec *c)
     return OK;
 }
 
-static int ap_http_create_req(request_rec *r)
-{
-    if (!r->main)
-    {
-        ap_add_input_filter("HTTP_IN", NULL, r, r->connection);
-    }
-    return OK;
-}
-
 static void ap_http_insert_filter(request_rec *r)
 {
     if (!r->main) {
@@ -328,8 +319,6 @@ static void register_hooks(apr_pool_t *p)
     ap_hook_map_to_storage(ap_send_http_trace,NULL,NULL,APR_HOOK_MIDDLE);
     ap_hook_http_method(http_method,NULL,NULL,APR_HOOK_REALLY_LAST);
     ap_hook_default_port(http_port,NULL,NULL,APR_HOOK_REALLY_LAST);
-    ap_hook_create_request(ap_http_create_req, NULL, NULL, APR_HOOK_MIDDLE);
-
     ap_hook_insert_filter(ap_http_insert_filter, NULL, NULL, APR_HOOK_REALLY_LAST);
     ap_register_input_filter("HTTP_IN", ap_http_filter, AP_FTYPE_CONNECTION);
     ap_register_output_filter("HTTP_HEADER", ap_http_header_filter, 
index 813e1c70bb7a09dd7fde76d709dd7b248d09f931..dd7c79eb2e21d7829db04744c9afefed0aeb3dbc 100644 (file)
@@ -484,7 +484,6 @@ AP_DECLARE(const char *) ap_method_name_of(int methnum)
 static long get_chunk_size(char *);
 
 typedef struct http_filter_ctx {
-    int status;
     apr_size_t remaining;
     enum {
         BODY_NONE,
@@ -493,8 +492,9 @@ typedef struct http_filter_ctx {
     } state;
 } http_ctx_t;
 
-/* Hi, I'm the main input filter for HTTP requests. 
- * I handle chunked and content-length bodies. */
+/* This is the input filter for HTTP requests.  It handles chunked and 
+ * content-length bodies.  This can only be inserted/used after the headers
+ * are successfully parsed. */
 apr_status_t ap_http_filter(ap_filter_t *f, apr_bucket_brigade *b, ap_input_mode_t mode, apr_off_t *readbytes)
 {
     apr_bucket *e;
@@ -502,45 +502,32 @@ apr_status_t ap_http_filter(ap_filter_t *f, apr_bucket_brigade *b, ap_input_mode
     apr_status_t rv;
 
     if (!ctx) {
-        f->ctx = ctx = apr_pcalloc(f->r->pool, sizeof(*ctx));
-        ctx->status = f->r->status;
-    }
-
-    /* Basically, we have to stay out of the way until server/protocol.c
-     * says it is okay - which it does by setting r->status to OK. */
-    if (f->r->status != ctx->status)
-    {
-        int old_status;
-        /* Allow us to be reentrant! */
-        old_status = ctx->status;
-        ctx->status = f->r->status;
+        const char *tenc, *lenp;
+        f->ctx = ctx = apr_palloc(f->r->pool, sizeof(*ctx));
+        ctx->state = BODY_NONE;
 
-        if (old_status == HTTP_REQUEST_TIME_OUT && f->r->status == HTTP_OK)
-        {
-            const char *tenc, *lenp;
-            tenc = apr_table_get(f->r->headers_in, "Transfer-Encoding");
-            lenp = apr_table_get(f->r->headers_in, "Content-Length");
+        tenc = apr_table_get(f->r->headers_in, "Transfer-Encoding");
+        lenp = apr_table_get(f->r->headers_in, "Content-Length");
 
-            if (tenc) {
-                if (!strcasecmp(tenc, "chunked")) {
-                    char line[30];
+        if (tenc) {
+            if (!strcasecmp(tenc, "chunked")) {
+                char line[30];
             
-                    if ((rv = ap_getline(line, sizeof(line), f->r, 0)) < 0) {
-                        return rv;
-                    }
-                    ctx->state = BODY_CHUNK;
-                    ctx->remaining = get_chunk_size(line);
+                if ((rv = ap_getline(line, sizeof(line), f->r, 0)) < 0) {
+                    return rv;
                 }
+                ctx->state = BODY_CHUNK;
+                ctx->remaining = get_chunk_size(line);
             }
-            else if (lenp) {
-                const char *pos = lenp;
-
-                while (apr_isdigit(*pos) || apr_isspace(*pos))
-                    ++pos;
-                if (*pos == '\0') {
-                    ctx->state = BODY_LENGTH;
-                    ctx->remaining = atol(lenp);
-                }
+        }
+        else if (lenp) {
+            const char *pos = lenp;
+
+            while (apr_isdigit(*pos) || apr_isspace(*pos))
+                ++pos;
+            if (*pos == '\0') {
+                ctx->state = BODY_LENGTH;
+                ctx->remaining = atol(lenp);
             }
         }
     }
@@ -575,6 +562,7 @@ apr_status_t ap_http_filter(ap_filter_t *f, apr_bucket_brigade *b, ap_input_mode
 
                 if (!ctx->remaining)
                 {
+                    /* Handle trailers by calling get_mime_headers again! */
                     e = apr_bucket_eos_create();
                     APR_BRIGADE_INSERT_TAIL(b, e);
                     return APR_SUCCESS;
index c6d18235d13a36f509802c61c6ae5571909e8018..3bdba03c5a1f0a51d8bba87d271b3c832194504e 100644 (file)
@@ -676,6 +676,8 @@ request_rec *ap_read_request(conn_rec *conn)
         }
     }
 
+    ap_add_input_filter("HTTP_IN", NULL, r, r->connection);
+
     if ((access_status = ap_run_post_read_request(r))) {
         ap_die(access_status, r);
         ap_run_log_transaction(r);