diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/http2/h2_from_h1.c | 77 | ||||
-rw-r--r-- | modules/http2/h2_headers.c | 14 | ||||
-rw-r--r-- | modules/http2/h2_headers.h | 6 |
3 files changed, 27 insertions, 70 deletions
diff --git a/modules/http2/h2_from_h1.c b/modules/http2/h2_from_h1.c index ff37d173d4..16a549a897 100644 --- a/modules/http2/h2_from_h1.c +++ b/modules/http2/h2_from_h1.c @@ -114,65 +114,11 @@ static void fix_vary(request_rec *r) } } -static void set_basic_http_header(apr_table_t *headers, request_rec *r, - apr_pool_t *pool) -{ - char *date = NULL; - const char *proxy_date = NULL; - const char *server = NULL; - const char *us = ap_get_server_banner(); - - /* - * keep the set-by-proxy server and date headers, otherwise - * generate a new server header / date header - */ - if (r && r->proxyreq != PROXYREQ_NONE) { - proxy_date = apr_table_get(r->headers_out, "Date"); - if (!proxy_date) { - /* - * proxy_date needs to be const. So use date for the creation of - * our own Date header and pass it over to proxy_date later to - * avoid a compiler warning. - */ - date = apr_palloc(pool, APR_RFC822_DATE_LEN); - ap_recent_rfc822_date(date, r->request_time); - } - server = apr_table_get(r->headers_out, "Server"); - } - else { - date = apr_palloc(pool, APR_RFC822_DATE_LEN); - ap_recent_rfc822_date(date, r? r->request_time : apr_time_now()); - } - - apr_table_setn(headers, "Date", proxy_date ? proxy_date : date ); - if (r) { - apr_table_unset(r->headers_out, "Date"); - } - - if (!server && *us) { - server = us; - } - if (server) { - apr_table_setn(headers, "Server", server); - if (r) { - apr_table_unset(r->headers_out, "Server"); - } - } -} - -static int copy_header(void *ctx, const char *name, const char *value) -{ - apr_table_t *headers = ctx; - - apr_table_add(headers, name, value); - return 1; -} - static h2_headers *create_response(h2_task *task, request_rec *r) { const char *clheader; const char *ctype; - apr_table_t *headers; + /* * Now that we are ready to send a response, we need to combine the two * header field tables into a single table. If we don't do this, our @@ -279,11 +225,24 @@ static h2_headers *create_response(h2_task *task, request_rec *r) apr_table_unset(r->headers_out, "Content-Length"); } - headers = apr_table_make(r->pool, 10); - set_basic_http_header(headers, r, r->pool); - apr_table_do(copy_header, headers, r->headers_out, NULL); + /* + * keep the set-by-proxy server and date headers, otherwise + * generate a new server header / date header + */ + if (r->proxyreq != PROXYREQ_RESPONSE + || !apr_table_get(r->headers_out, "Date")) { + char *date = apr_palloc(r->pool, APR_RFC822_DATE_LEN); + ap_recent_rfc822_date(date, r? r->request_time : apr_time_now()); + apr_table_setn(r->headers_out, "Date", date ); + } + if (r->proxyreq != PROXYREQ_RESPONSE) { + const char *us = ap_get_server_banner(); + if (us) { + apr_table_setn(r->headers_out, "Server", us); + } + } - return h2_headers_rcreate(r, r->status, headers, r->pool); + return h2_headers_rcreate(r, r->status, r->headers_out, r->pool); } typedef enum { diff --git a/modules/http2/h2_headers.c b/modules/http2/h2_headers.c index 271b1f1c61..b4e18f2127 100644 --- a/modules/http2/h2_headers.c +++ b/modules/http2/h2_headers.c @@ -113,9 +113,9 @@ apr_bucket *h2_bucket_headers_beam(struct h2_bucket_beam *beam, } -h2_headers *h2_headers_create(int status, apr_table_t *headers_in, - apr_table_t *notes, apr_off_t raw_bytes, - apr_pool_t *pool) +h2_headers *h2_headers_create(int status, const apr_table_t *headers_in, + const apr_table_t *notes, apr_off_t raw_bytes, + apr_pool_t *pool) { h2_headers *headers = apr_pcalloc(pool, sizeof(h2_headers)); headers->status = status; @@ -141,7 +141,7 @@ apr_size_t h2_headers_length(h2_headers *headers) } h2_headers *h2_headers_rcreate(request_rec *r, int status, - apr_table_t *header, apr_pool_t *pool) + const apr_table_t *header, apr_pool_t *pool) { h2_headers *headers = h2_headers_create(status, header, r->notes, 0, pool); if (headers->status == HTTP_FORBIDDEN) { @@ -172,14 +172,12 @@ h2_headers *h2_headers_rcreate(request_rec *r, int status, h2_headers *h2_headers_copy(apr_pool_t *pool, h2_headers *h) { - return h2_headers_create(h->status, apr_table_copy(pool, h->headers), - apr_table_copy(pool, h->notes), h->raw_bytes, pool); + return h2_headers_create(h->status, h->headers, h->notes, h->raw_bytes, pool); } h2_headers *h2_headers_clone(apr_pool_t *pool, h2_headers *h) { - return h2_headers_create(h->status, apr_table_clone(pool, h->headers), - apr_table_clone(pool, h->notes), h->raw_bytes, pool); + return h2_headers_create(h->status, h->headers, h->notes, h->raw_bytes, pool); } h2_headers *h2_headers_die(apr_status_t type, diff --git a/modules/http2/h2_headers.h b/modules/http2/h2_headers.h index 3f6ecd07ae..fbaf68785f 100644 --- a/modules/http2/h2_headers.h +++ b/modules/http2/h2_headers.h @@ -44,8 +44,8 @@ apr_bucket *h2_bucket_headers_beam(struct h2_bucket_beam *beam, * @param raw_bytes the raw network bytes (if known) used to transmit these * @param pool the memory pool to use */ -h2_headers *h2_headers_create(int status, apr_table_t *header, - apr_table_t *notes, apr_off_t raw_bytes, +h2_headers *h2_headers_create(int status, const apr_table_t *header, + const apr_table_t *notes, apr_off_t raw_bytes, apr_pool_t *pool); /** @@ -56,7 +56,7 @@ h2_headers *h2_headers_create(int status, apr_table_t *header, * @param pool the memory pool to use */ h2_headers *h2_headers_rcreate(request_rec *r, int status, - apr_table_t *header, apr_pool_t *pool); + const apr_table_t *header, apr_pool_t *pool); /** * Copy the headers into another pool. This will not copy any |