[nginx] Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin
mdounin at mdounin.ru
Mon Jun 10 10:37:46 UTC 2013
details: http://hg.nginx.org/nginx/rev/f5626ab8cb87
branches:
changeset: 5248:f5626ab8cb87
user: Maxim Dounin <mdounin at mdounin.ru>
date: Mon Jun 10 14:35:00 2013 +0400
description:
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.
diffstat:
src/http/modules/perl/nginx.xs | 36 +++++++++++++++++++++++++++---------
1 files changed, 27 insertions(+), 9 deletions(-)
diffs (88 lines):
diff --git a/src/http/modules/perl/nginx.xs b/src/http/modules/perl/nginx.xs
--- a/src/http/modules/perl/nginx.xs
+++ b/src/http/modules/perl/nginx.xs
@@ -222,10 +222,11 @@ header_in(r, key)
dXSTARG;
ngx_http_request_t *r;
SV *key;
- u_char *p, *lowcase_key, *cookie;
+ u_char *p, *lowcase_key, *value, sep;
STRLEN len;
ssize_t size;
ngx_uint_t i, n, hash;
+ ngx_array_t *a;
ngx_list_part_t *part;
ngx_table_elt_t *h, **ph;
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);
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) {
ph = (ngx_table_elt_t **) ((char *) &r->headers_in + hh->offset);
@@ -268,15 +282,19 @@ header_in(r, key)
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) {
XSRETURN_UNDEF;
}
- ph = r->headers_in.cookies.elts;
+ ph = a->elts;
if (n == 1) {
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;
}
- cookie = ngx_pnalloc(r->pool, size);
- if (cookie == NULL) {
+ value = ngx_pnalloc(r->pool, size);
+ if (value == NULL) {
XSRETURN_UNDEF;
}
- p = cookie;
+ p = value;
for (i = 0; /* void */ ; i++) {
p = ngx_copy(p, ph[i]->value.data, ph[i]->value.len);
@@ -304,10 +322,10 @@ header_in(r, key)
break;
}
- *p++ = ';'; *p++ = ' ';
+ *p++ = sep; *p++ = ' ';
}
- ngx_http_perl_set_targ(cookie, size);
+ ngx_http_perl_set_targ(value, size);
goto done;
}
More information about the nginx-devel
mailing list