From 66ee5533d3056e0b95724e9693db6d0844b3a08b Mon Sep 17 00:00:00 2001 From: Justin Erenkrantz Date: Sat, 29 Sep 2001 08:48:59 +0000 Subject: [PATCH] Remove the lameo create_req hack and delay the addition of the HTTP_IN 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 | 11 ------- modules/http/http_protocol.c | 62 +++++++++++++++--------------------- server/protocol.c | 2 ++ 3 files changed, 27 insertions(+), 48 deletions(-) diff --git a/modules/http/http_core.c b/modules/http/http_core.c index fc51a1558c..be64ced5eb 100644 --- a/modules/http/http_core.c +++ b/modules/http/http_core.c @@ -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, diff --git a/modules/http/http_protocol.c b/modules/http/http_protocol.c index 813e1c70bb..dd7c79eb2e 100644 --- a/modules/http/http_protocol.c +++ b/modules/http/http_protocol.c @@ -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; diff --git a/server/protocol.c b/server/protocol.c index c6d18235d1..3bdba03c5a 100644 --- a/server/protocol.c +++ b/server/protocol.c @@ -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); -- 2.50.1