httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@locus.apache.org
Subject cvs commit: apache-2.0/src/main http_protocol.c
Date Wed, 01 Nov 2000 05:15:26 GMT
rbb         00/10/31 21:15:26

  Modified:    src/main http_protocol.c
  Log:
  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.
  
  Revision  Changes    Path
  1.214     +21 -10    apache-2.0/src/main/http_protocol.c
  
  Index: http_protocol.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/main/http_protocol.c,v
  retrieving revision 1.213
  retrieving revision 1.214
  diff -u -r1.213 -r1.214
  --- http_protocol.c	2000/11/01 00:52:06	1.213
  +++ http_protocol.c	2000/11/01 05:15:25	1.214
  @@ -1773,6 +1773,14 @@
       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 @@
       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 @@
   	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) {
  @@ -2401,6 +2400,18 @@
           apr_rfc822_date(date, r->request_time);
           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;
  
  
  

Mime
View raw message