Mercurial > hg > nginx
comparison src/http/ngx_http_upstream.c @ 5677:3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Tue, 29 Apr 2014 12:28:41 +0400 |
parents | 16405e02e612 |
children | 110b50657d77 |
comparison
equal
deleted
inserted
replaced
5676:fbfdf8017748 | 5677:3a48775f1535 |
---|---|
214 { ngx_string("Refresh"), | 214 { ngx_string("Refresh"), |
215 ngx_http_upstream_ignore_header_line, 0, | 215 ngx_http_upstream_ignore_header_line, 0, |
216 ngx_http_upstream_rewrite_refresh, 0, 0 }, | 216 ngx_http_upstream_rewrite_refresh, 0, 0 }, |
217 | 217 |
218 { ngx_string("Set-Cookie"), | 218 { ngx_string("Set-Cookie"), |
219 ngx_http_upstream_process_set_cookie, 0, | 219 ngx_http_upstream_process_set_cookie, |
220 offsetof(ngx_http_upstream_headers_in_t, cookies), | |
220 ngx_http_upstream_rewrite_set_cookie, 0, 1 }, | 221 ngx_http_upstream_rewrite_set_cookie, 0, 1 }, |
221 | 222 |
222 { ngx_string("Content-Disposition"), | 223 { ngx_string("Content-Disposition"), |
223 ngx_http_upstream_ignore_header_line, 0, | 224 ngx_http_upstream_ignore_header_line, 0, |
224 ngx_http_upstream_copy_header_line, 0, 1 }, | 225 ngx_http_upstream_copy_header_line, 0, 1 }, |
3729 | 3730 |
3730 static ngx_int_t | 3731 static ngx_int_t |
3731 ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, ngx_table_elt_t *h, | 3732 ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, ngx_table_elt_t *h, |
3732 ngx_uint_t offset) | 3733 ngx_uint_t offset) |
3733 { | 3734 { |
3735 ngx_array_t *pa; | |
3736 ngx_table_elt_t **ph; | |
3737 ngx_http_upstream_t *u; | |
3738 | |
3739 u = r->upstream; | |
3740 pa = &u->headers_in.cookies; | |
3741 | |
3742 if (pa->elts == NULL) { | |
3743 if (ngx_array_init(pa, r->pool, 1, sizeof(ngx_table_elt_t *)) != NGX_OK) | |
3744 { | |
3745 return NGX_ERROR; | |
3746 } | |
3747 } | |
3748 | |
3749 ph = ngx_array_push(pa); | |
3750 if (ph == NULL) { | |
3751 return NGX_ERROR; | |
3752 } | |
3753 | |
3754 *ph = h; | |
3755 | |
3734 #if (NGX_HTTP_CACHE) | 3756 #if (NGX_HTTP_CACHE) |
3735 ngx_http_upstream_t *u; | |
3736 | |
3737 u = r->upstream; | |
3738 | |
3739 if (!(u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_SET_COOKIE)) { | 3757 if (!(u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_SET_COOKIE)) { |
3740 u->cacheable = 0; | 3758 u->cacheable = 0; |
3741 } | 3759 } |
3742 #endif | 3760 #endif |
3743 | 3761 |
4652 } | 4670 } |
4653 | 4671 |
4654 return ngx_http_variable_unknown_header(v, (ngx_str_t *) data, | 4672 return ngx_http_variable_unknown_header(v, (ngx_str_t *) data, |
4655 &r->upstream->headers_in.headers.part, | 4673 &r->upstream->headers_in.headers.part, |
4656 sizeof("upstream_http_") - 1); | 4674 sizeof("upstream_http_") - 1); |
4675 } | |
4676 | |
4677 | |
4678 ngx_int_t | |
4679 ngx_http_upstream_cookie_variable(ngx_http_request_t *r, | |
4680 ngx_http_variable_value_t *v, uintptr_t data) | |
4681 { | |
4682 ngx_str_t *name = (ngx_str_t *) data; | |
4683 | |
4684 ngx_str_t cookie, s; | |
4685 | |
4686 if (r->upstream == NULL) { | |
4687 v->not_found = 1; | |
4688 return NGX_OK; | |
4689 } | |
4690 | |
4691 s.len = name->len - (sizeof("upstream_cookie_") - 1); | |
4692 s.data = name->data + sizeof("upstream_cookie_") - 1; | |
4693 | |
4694 if (ngx_http_parse_set_cookie_lines(&r->upstream->headers_in.cookies, | |
4695 &s, &cookie) | |
4696 == NGX_DECLINED) | |
4697 { | |
4698 v->not_found = 1; | |
4699 return NGX_OK; | |
4700 } | |
4701 | |
4702 v->len = cookie.len; | |
4703 v->valid = 1; | |
4704 v->no_cacheable = 0; | |
4705 v->not_found = 0; | |
4706 v->data = cookie.data; | |
4707 | |
4708 return NGX_OK; | |
4657 } | 4709 } |
4658 | 4710 |
4659 | 4711 |
4660 #if (NGX_HTTP_CACHE) | 4712 #if (NGX_HTTP_CACHE) |
4661 | 4713 |