aboutsummaryrefslogtreecommitdiff
path: root/src/http/ngx_http_core_module.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/http/ngx_http_core_module.c')
-rw-r--r--src/http/ngx_http_core_module.c134
1 files changed, 113 insertions, 21 deletions
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 72e67544c..78a9e5ea7 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -1007,6 +1007,7 @@ ngx_http_core_find_config_phase(ngx_http_request_t *r,
}
r->headers_out.location->hash = 1;
+ r->headers_out.location->next = NULL;
ngx_str_set(&r->headers_out.location->key, "Location");
if (r->args.len == 0) {
@@ -1087,6 +1088,7 @@ ngx_int_t
ngx_http_core_access_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
{
ngx_int_t rc;
+ ngx_table_elt_t *h;
ngx_http_core_loc_conf_t *clcf;
if (r != r->main) {
@@ -1121,8 +1123,8 @@ ngx_http_core_access_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph)
if (rc == NGX_OK) {
r->access_code = 0;
- if (r->headers_out.www_authenticate) {
- r->headers_out.www_authenticate->hash = 0;
+ for (h = r->headers_out.www_authenticate; h; h = h->next) {
+ h->hash = 0;
}
r->phase_handler = ph->next;
@@ -1687,6 +1689,7 @@ ngx_http_set_etag(ngx_http_request_t *r)
}
etag->hash = 1;
+ etag->next = NULL;
ngx_str_set(&etag->key, "ETag");
etag->value.data = ngx_pnalloc(r->pool, NGX_OFF_T_LEN + NGX_TIME_T_LEN + 3);
@@ -1781,6 +1784,7 @@ ngx_http_send_response(ngx_http_request_t *r, ngx_uint_t status,
}
r->headers_out.location->hash = 1;
+ r->headers_out.location->next = NULL;
ngx_str_set(&r->headers_out.location->key, "Location");
r->headers_out.location->value = val;
@@ -2024,8 +2028,7 @@ ngx_http_gzip_ok(ngx_http_request_t *r)
{
time_t date, expires;
ngx_uint_t p;
- ngx_array_t *cc;
- ngx_table_elt_t *e, *d, *ae;
+ ngx_table_elt_t *e, *d, *ae, *cc;
ngx_http_core_loc_conf_t *clcf;
r->gzip_tested = 1;
@@ -2118,30 +2121,30 @@ ngx_http_gzip_ok(ngx_http_request_t *r)
return NGX_DECLINED;
}
- cc = &r->headers_out.cache_control;
+ cc = r->headers_out.cache_control;
- if (cc->elts) {
+ if (cc) {
if ((p & NGX_HTTP_GZIP_PROXIED_NO_CACHE)
- && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_cache,
+ && ngx_http_parse_multi_header_lines(r, cc, &ngx_http_gzip_no_cache,
NULL)
- >= 0)
+ != NULL)
{
goto ok;
}
if ((p & NGX_HTTP_GZIP_PROXIED_NO_STORE)
- && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_no_store,
+ && ngx_http_parse_multi_header_lines(r, cc, &ngx_http_gzip_no_store,
NULL)
- >= 0)
+ != NULL)
{
goto ok;
}
if ((p & NGX_HTTP_GZIP_PROXIED_PRIVATE)
- && ngx_http_parse_multi_header_lines(cc, &ngx_http_gzip_private,
+ && ngx_http_parse_multi_header_lines(r, cc, &ngx_http_gzip_private,
NULL)
- >= 0)
+ != NULL)
{
goto ok;
}
@@ -2712,12 +2715,12 @@ ngx_http_set_disable_symlinks(ngx_http_request_t *r,
ngx_int_t
ngx_http_get_forwarded_addr(ngx_http_request_t *r, ngx_addr_t *addr,
- ngx_array_t *headers, ngx_str_t *value, ngx_array_t *proxies,
+ ngx_table_elt_t *headers, ngx_str_t *value, ngx_array_t *proxies,
int recursive)
{
- ngx_int_t rc;
- ngx_uint_t i, found;
- ngx_table_elt_t **h;
+ ngx_int_t rc;
+ ngx_uint_t found;
+ ngx_table_elt_t *h, *next;
if (headers == NULL) {
return ngx_http_get_forwarded_addr_internal(r, addr, value->data,
@@ -2725,16 +2728,23 @@ ngx_http_get_forwarded_addr(ngx_http_request_t *r, ngx_addr_t *addr,
recursive);
}
- i = headers->nelts;
- h = headers->elts;
+ /* revert headers order */
+
+ for (h = headers, headers = NULL; h; h = next) {
+ next = h->next;
+ h->next = headers;
+ headers = h;
+ }
+
+ /* iterate over all headers in reverse order */
rc = NGX_DECLINED;
found = 0;
- while (i-- > 0) {
- rc = ngx_http_get_forwarded_addr_internal(r, addr, h[i]->value.data,
- h[i]->value.len, proxies,
+ for (h = headers; h; h = h->next) {
+ rc = ngx_http_get_forwarded_addr_internal(r, addr, h->value.data,
+ h->value.len, proxies,
recursive);
if (!recursive) {
@@ -2753,6 +2763,14 @@ ngx_http_get_forwarded_addr(ngx_http_request_t *r, ngx_addr_t *addr,
found = 1;
}
+ /* restore headers order */
+
+ for (h = headers, headers = NULL; h; h = next) {
+ next = h->next;
+ h->next = headers;
+ headers = h;
+ }
+
return rc;
}
@@ -2802,6 +2820,80 @@ ngx_http_get_forwarded_addr_internal(ngx_http_request_t *r, ngx_addr_t *addr,
}
+ngx_int_t
+ngx_http_link_multi_headers(ngx_http_request_t *r)
+{
+ ngx_uint_t i, j;
+ ngx_list_part_t *part, *ppart;
+ ngx_table_elt_t *header, *pheader, **ph;
+
+ if (r->headers_in.multi_linked) {
+ return NGX_OK;
+ }
+
+ r->headers_in.multi_linked = 1;
+
+ part = &r->headers_in.headers.part;
+ header = part->elts;
+
+ for (i = 0; /* void */; i++) {
+
+ if (i >= part->nelts) {
+ if (part->next == NULL) {
+ break;
+ }
+
+ part = part->next;
+ header = part->elts;
+ i = 0;
+ }
+
+ header[i].next = NULL;
+
+ /*
+ * search for previous headers with the same name;
+ * if there are any, link to them
+ */
+
+ ppart = &r->headers_in.headers.part;
+ pheader = ppart->elts;
+
+ for (j = 0; /* void */; j++) {
+
+ if (j >= ppart->nelts) {
+ if (ppart->next == NULL) {
+ break;
+ }
+
+ ppart = ppart->next;
+ pheader = ppart->elts;
+ j = 0;
+ }
+
+ if (part == ppart && i == j) {
+ break;
+ }
+
+ if (header[i].key.len == pheader[j].key.len
+ && ngx_strncasecmp(header[i].key.data, pheader[j].key.data,
+ header[i].key.len)
+ == 0)
+ {
+ ph = &pheader[j].next;
+ while (*ph) { ph = &(*ph)->next; }
+ *ph = &header[i];
+
+ r->headers_in.multi = 1;
+
+ break;
+ }
+ }
+ }
+
+ return NGX_OK;
+}
+
+
static char *
ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
{