From 39a227d48d4513f30afb4b6f043695ded639460f Mon Sep 17 00:00:00 2001 From: Brian Pane Date: Mon, 7 Oct 2002 05:10:54 +0000 Subject: [PATCH] Simpler, faster code for generating HTTP response headers: 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 | 3 +++ modules/http/http_protocol.c | 45 ++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 4807fd1fe2..5fec8e69d7 100644 --- 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 ] diff --git a/modules/http/http_protocol.c b/modules/http/http_protocol.c index 677d60def5..b4efb09bb9 100644 --- a/modules/http/http_protocol.c +++ b/modules/http/http_protocol.c @@ -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); -- 2.40.0