From bb8525b09d5c5bc9e4cefeec735a65de4feb5ca2 Mon Sep 17 00:00:00 2001 From: Ryan Bloom Date: Fri, 6 Oct 2000 06:07:07 +0000 Subject: [PATCH] Add the first draft of the http_filter. In time this filter will split the bucket brigade between the headers and the body. Right now it just converts \r\n to \n\0. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@86412 13f79535-47bb-0310-9956-ffa450edef68 --- include/http_protocol.h | 4 ++++ modules/http/http_core.c | 1 + modules/http/http_protocol.c | 40 +++++++++++++++++++++++++----------- server/connection.c | 1 + 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/include/http_protocol.h b/include/http_protocol.h index 1e4f2ef299..a368646ba4 100644 --- a/include/http_protocol.h +++ b/include/http_protocol.h @@ -62,6 +62,8 @@ #include "ap_hooks.h" #include "apr_portable.h" #include "apr_mmap.h" +#include "util_filter.h" +#include "ap_buckets.h" #ifdef __cplusplus extern "C" { @@ -544,6 +546,8 @@ API_EXPORT(int) ap_method_number_of(const char *method); */ API_EXPORT(const char *) ap_method_name_of(int methnum); +int http_filter(ap_filter_t *f, ap_bucket_brigade *b); + /* Hooks */ /* * post_read_request --- run right after read_request or internal_redirect, diff --git a/modules/http/http_core.c b/modules/http/http_core.c index dc1bf2ddd1..6c8f8fdbc4 100644 --- a/modules/http/http_core.c +++ b/modules/http/http_core.c @@ -3478,6 +3478,7 @@ static void register_hooks(void) * request-processing time. */ ap_hook_insert_filter(core_register_filter, NULL, NULL, AP_HOOK_MIDDLE); + ap_register_input_filter("HTTP_IN", http_filter, AP_FTYPE_CONNECTION); ap_register_input_filter("CORE_IN", core_input_filter, AP_FTYPE_CONNECTION); ap_register_output_filter("CORE", core_output_filter, AP_FTYPE_CONNECTION + 1); ap_register_output_filter("CHUNK", chunk_filter, AP_FTYPE_CONNECTION); diff --git a/modules/http/http_protocol.c b/modules/http/http_protocol.c index 3ae2198bcd..a3ebf727e0 100644 --- a/modules/http/http_protocol.c +++ b/modules/http/http_protocol.c @@ -856,6 +856,33 @@ API_EXPORT(const char *) ap_method_name_of(int methnum) return AP_HTTP_METHODS[methnum]; } +int http_filter(ap_filter_t *f, ap_bucket_brigade *b) +{ +#define ASCII_CR '\015' +#define ASCII_LF '\012' + ap_bucket *e; + char *buff; + int length; + char *pos; + + ap_get_brigade(f->next, b); + + AP_BRIGADE_FOREACH(e, b) { + + e->read(e, (const char **)&buff, &length, 0); + + pos = buff + 1; + while (pos < buff + length) { + if ((*pos == ASCII_LF) && (*(pos - 1) == ASCII_CR)) { + *(pos - 1) = ASCII_LF; + *pos = '\0'; + } + pos++; + } + } + return APR_SUCCESS; +} + /* Get a line of protocol input, including any continuation lines * caused by MIME folding (or broken clients) if fold != 0, and place it * in the buffer s, of size n bytes, without the ending newline. @@ -880,8 +907,6 @@ static int getline(char *s, int n, conn_rec *c, int fold) ap_bucket_brigade *b; ap_bucket *e; -#define ASCII_CR '\015' -#define ASCII_LF '\012' #ifdef APACHE_XLATE_XXX /* When getline() is called, the HTTP protocol is in a state @@ -938,18 +963,9 @@ static int getline(char *s, int n, conn_rec *c, int fold) */ if ((toss = ap_strchr_c(temp, ASCII_LF)) != NULL) { length = toss - temp + 1; - e->split(e, length); + e->split(e, length + 1); apr_cpystrn(pos, temp, length + 1); - /* get rid of optional \r, again using ascii encoding */ - - /*** XXX need 2 sentinels in front of pos - *** which are never ASCII_CR, in case length < 2 - */ - if (pos[length - 2] == ASCII_CR) { - pos[length - 2] = ASCII_LF; - pos[--length] = '\0'; - } AP_BUCKET_REMOVE(e); e->destroy(e); } diff --git a/server/connection.c b/server/connection.c index e1b56fed52..92a4d22cf3 100644 --- a/server/connection.c +++ b/server/connection.c @@ -216,6 +216,7 @@ CORE_EXPORT(void) ap_process_connection(conn_rec *c) int ap_pre_http_connection(conn_rec *c) { + ap_add_input_filter("HTTP_IN", NULL, NULL, c); ap_add_input_filter("CORE_IN", NULL, NULL, c); ap_add_output_filter("CORE", NULL, NULL, c); return OK; -- 2.40.0