]> granicus.if.org Git - apache/commitdiff
Simpler, faster code for generating HTTP response headers:
authorBrian Pane <brianp@apache.org>
Mon, 7 Oct 2002 05:10:54 +0000 (05:10 +0000)
committerBrian Pane <brianp@apache.org>
Mon, 7 Oct 2002 05:10:54 +0000 (05:10 +0000)
Instead of passing a callback function to apr_table_do() to
generate one field at a time, just build an iovec containing
all the fields and make a single call to apr_brigade_writev().

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@97122 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
modules/http/http_protocol.c

diff --git a/CHANGES b/CHANGES
index 4807fd1fe21531a33ce9f5a1f77d4134af3c68a9..5fec8e69d7b7a857b9daa821fb85304f5c7f85af 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,8 @@
 Changes with Apache 2.0.44
 
+  *) Performance improvements for the code that generates HTTP
+     response headers  [Brian Pane]
+
   *) Add -S as a synonym for -t -DDUMP_VHOSTS.
      [Thom May <thom@planetarytramp.net>]
 
index 677d60def5384989ac6ba08ff1161a83fb8e36b6..b4efb09bb919b9465a3c44eb10848cf72f59a38e 100644 (file)
@@ -1151,6 +1151,48 @@ static int form_header_field(header_struct *h,
     return 1;
 }
 
+/* Send a request's HTTP response headers to the client.
+ */
+static apr_status_t send_all_header_fields(header_struct *h,
+                                           const request_rec *r)
+{
+    const apr_array_header_t *elts;
+    const apr_table_entry_t *t_elt;
+    const apr_table_entry_t *t_end;
+    struct iovec *vec;
+    struct iovec *vec_next;
+
+    elts = apr_table_elts(r->headers_out);
+    if (elts->nelts == 0) {
+        return APR_SUCCESS;
+    }
+    t_elt = (const apr_table_entry_t *)(elts->elts);
+    t_end = t_elt + elts->nelts;
+    vec = (struct iovec *)apr_palloc(h->pool, 4 * elts->nelts);
+    vec_next = vec;
+
+    /* For each field, generate
+     *    name ": " value CRLF
+     */
+    do {
+        vec_next->iov_base = (void*)(t_elt->key);
+        vec_next->iov_len = strlen(t_elt->key);
+        vec_next++;
+        vec_next->iov_base = ": ";
+        vec_next->iov_len = sizeof(": ") - 1;
+        vec_next++;
+        vec_next->iov_base = (void*)(t_elt->val);
+        vec_next->iov_len = strlen(t_elt->val);
+        vec_next++;
+        vec_next->iov_base = CRLF;
+        vec_next->iov_len = sizeof(CRLF) - 1;
+        vec_next++;
+        t_elt++;
+    } while (t_elt < t_end);
+
+    return apr_brigade_writev(h->bb, NULL, NULL, vec, vec_next - vec);
+}
+
 /*
  * Determine the protocol to use for the response. Potentially downgrade
  * to HTTP/1.0 in some situations and/or turn off keepalives.
@@ -1637,8 +1679,7 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_http_header_filter(ap_filter_t *f,
                      NULL);
     }
     else {
-        apr_table_do((int (*) (void *, const char *, const char *)) form_header_field,
-                     (void *) &h, r->headers_out, NULL);
+        send_all_header_fields(&h, r);
     }
 
     terminate_header(b2);