From: Ryan Bloom Date: Wed, 1 Nov 2000 05:15:25 +0000 (+0000) Subject: Stop always allocating 8k for each request. We now count the number X-Git-Tag: APACHE_2_0_ALPHA_8~213 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7998ed4b01e94282e82d0193912fbc0ba88d9197;p=apache Stop always allocating 8k for each request. We now count the number of bytes required for the headers for each request, and we just allocate that number of bytes plus 100 extra. The extra 100 are a fudge factor, because it is a bit difficult to compute the exact length for the basic HTTP headers like date and the status line. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@86781 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/http/http_protocol.c b/modules/http/http_protocol.c index 9480474d70..507a1b2aed 100644 --- a/modules/http/http_protocol.c +++ b/modules/http/http_protocol.c @@ -1773,6 +1773,14 @@ static int form_header_field(header_struct *h, return 1; } +static int compute_header_len(apr_size_t *length, const char *fieldname, + const char *fieldval) +{ + /* The extra five are for ": " and CRLF, plus one for a '\0'. */ + *length = *length + strlen(fieldname) + strlen(fieldval) + 6; + return 1; +} + AP_DECLARE(void) ap_basic_http_header(request_rec *r, char *buf) { char *protocol; @@ -2311,7 +2319,7 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_http_header_filter(ap_filter_t *f, ap_bu char *buff; ap_bucket *e; ap_bucket_brigade *b2; - apr_size_t len; + apr_size_t len = 0; header_struct h; if (r->assbackwards) { @@ -2345,15 +2353,6 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_http_header_filter(ap_filter_t *f, ap_bu fixup_vary(r); } - /* XXX Should count the bytes in the headers and allocate just enough - * for the headers we have. - */ - buff = apr_pcalloc(r->pool, HUGE_STRING_LEN); - len = HUGE_STRING_LEN; - e = ap_bucket_create_pool(buff, len, r->pool); - ap_basic_http_header(r, buff); - buff += strlen(buff) + 1; - ap_set_keepalive(r); if (r->chunked) { @@ -2402,6 +2401,18 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_http_header_filter(ap_filter_t *f, ap_bu apr_table_addn(r->headers_out, "Expires", date); } + apr_table_do((int (*) (void *, const char *, const char *)) compute_header_len, + (void *) &len, r->headers_out, NULL); + + /* Need to add a fudge factor so that the CRLF at the end of the headers + * and the basic http headers don't overflow this buffer. + */ + len += strlen(ap_get_server_version()) + 100; + buff = apr_pcalloc(r->pool, len); + e = ap_bucket_create_pool(buff, len, r->pool); + ap_basic_http_header(r, buff); + buff += strlen(buff) + 1; + h.r = r; h.buf = buff;