mirror of
https://github.com/nginx/nginx.git
synced 2024-12-01 11:19:00 +08:00
Perl: fixed r->header_in("Cookie") (ticket #351).
It was broken by X-Forwarded-For related changes in f7fe817c92a2 (1.3.14) as hh->offset is no longer 0 for Cookie.
This commit is contained in:
parent
dc5c6928fb
commit
ddece08218
@ -222,10 +222,11 @@ header_in(r, key)
|
|||||||
dXSTARG;
|
dXSTARG;
|
||||||
ngx_http_request_t *r;
|
ngx_http_request_t *r;
|
||||||
SV *key;
|
SV *key;
|
||||||
u_char *p, *lowcase_key, *cookie;
|
u_char *p, *lowcase_key, *value, sep;
|
||||||
STRLEN len;
|
STRLEN len;
|
||||||
ssize_t size;
|
ssize_t size;
|
||||||
ngx_uint_t i, n, hash;
|
ngx_uint_t i, n, hash;
|
||||||
|
ngx_array_t *a;
|
||||||
ngx_list_part_t *part;
|
ngx_list_part_t *part;
|
||||||
ngx_table_elt_t *h, **ph;
|
ngx_table_elt_t *h, **ph;
|
||||||
ngx_http_header_t *hh;
|
ngx_http_header_t *hh;
|
||||||
@ -255,6 +256,19 @@ header_in(r, key)
|
|||||||
hh = ngx_hash_find(&cmcf->headers_in_hash, hash, lowcase_key, len);
|
hh = ngx_hash_find(&cmcf->headers_in_hash, hash, lowcase_key, len);
|
||||||
|
|
||||||
if (hh) {
|
if (hh) {
|
||||||
|
|
||||||
|
if (hh->offset == offsetof(ngx_http_headers_in_t, cookies)) {
|
||||||
|
sep = ';';
|
||||||
|
goto multi;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (NGX_HTTP_X_FORWARDED_FOR)
|
||||||
|
if (hh->offset == offsetof(ngx_http_headers_in_t, x_forwarded_for)) {
|
||||||
|
sep = ',';
|
||||||
|
goto multi;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (hh->offset) {
|
if (hh->offset) {
|
||||||
|
|
||||||
ph = (ngx_table_elt_t **) ((char *) &r->headers_in + hh->offset);
|
ph = (ngx_table_elt_t **) ((char *) &r->headers_in + hh->offset);
|
||||||
@ -268,15 +282,19 @@ header_in(r, key)
|
|||||||
XSRETURN_UNDEF;
|
XSRETURN_UNDEF;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cookie */
|
multi:
|
||||||
|
|
||||||
n = r->headers_in.cookies.nelts;
|
/* Cookie, X-Forwarded-For */
|
||||||
|
|
||||||
|
a = (ngx_array_t *) ((char *) &r->headers_in + hh->offset);
|
||||||
|
|
||||||
|
n = a->nelts;
|
||||||
|
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
XSRETURN_UNDEF;
|
XSRETURN_UNDEF;
|
||||||
}
|
}
|
||||||
|
|
||||||
ph = r->headers_in.cookies.elts;
|
ph = a->elts;
|
||||||
|
|
||||||
if (n == 1) {
|
if (n == 1) {
|
||||||
ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len);
|
ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len);
|
||||||
@ -290,12 +308,12 @@ header_in(r, key)
|
|||||||
size += ph[i]->value.len + sizeof("; ") - 1;
|
size += ph[i]->value.len + sizeof("; ") - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cookie = ngx_pnalloc(r->pool, size);
|
value = ngx_pnalloc(r->pool, size);
|
||||||
if (cookie == NULL) {
|
if (value == NULL) {
|
||||||
XSRETURN_UNDEF;
|
XSRETURN_UNDEF;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = cookie;
|
p = value;
|
||||||
|
|
||||||
for (i = 0; /* void */ ; i++) {
|
for (i = 0; /* void */ ; i++) {
|
||||||
p = ngx_copy(p, ph[i]->value.data, ph[i]->value.len);
|
p = ngx_copy(p, ph[i]->value.data, ph[i]->value.len);
|
||||||
@ -304,10 +322,10 @@ header_in(r, key)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*p++ = ';'; *p++ = ' ';
|
*p++ = sep; *p++ = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
ngx_http_perl_set_targ(cookie, size);
|
ngx_http_perl_set_targ(value, size);
|
||||||
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user