]> granicus.if.org Git - apache/commitdiff
Stop always allocating 8k for each request. We now count the number
authorRyan Bloom <rbb@apache.org>
Wed, 1 Nov 2000 05:15:25 +0000 (05:15 +0000)
committerRyan Bloom <rbb@apache.org>
Wed, 1 Nov 2000 05:15:25 +0000 (05:15 +0000)
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

modules/http/http_protocol.c

index 9480474d70bb0b4cd9ebcc4691e79ab320012318..507a1b2aedcf26499de9649d2cb02bd41198d637 100644 (file)
@@ -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;