aboutsummaryrefslogtreecommitdiff
path: root/src/http/modules/perl/nginx.xs
diff options
context:
space:
mode:
Diffstat (limited to 'src/http/modules/perl/nginx.xs')
-rw-r--r--src/http/modules/perl/nginx.xs116
1 files changed, 49 insertions, 67 deletions
diff --git a/src/http/modules/perl/nginx.xs b/src/http/modules/perl/nginx.xs
index caf7c084a..fd59e29ea 100644
--- a/src/http/modules/perl/nginx.xs
+++ b/src/http/modules/perl/nginx.xs
@@ -269,10 +269,9 @@ header_in(r, key)
u_char *p, *lowcase_key, *value, sep;
STRLEN len;
ssize_t size;
- ngx_uint_t i, n, hash;
- ngx_array_t *a;
+ ngx_uint_t i, hash;
ngx_list_part_t *part;
- ngx_table_elt_t *h, **ph;
+ ngx_table_elt_t *h, *header, **ph;
ngx_http_header_t *hh;
ngx_http_core_main_conf_t *cmcf;
@@ -302,78 +301,23 @@ header_in(r, key)
if (hh) {
- if (hh->offset == offsetof(ngx_http_headers_in_t, cookies)) {
+ if (hh->offset == offsetof(ngx_http_headers_in_t, cookie)) {
sep = ';';
- goto multi;
- }
-#if (NGX_HTTP_X_FORWARDED_FOR)
- if (hh->offset == offsetof(ngx_http_headers_in_t, x_forwarded_for)) {
+
+ } else {
sep = ',';
- goto multi;
}
-#endif
ph = (ngx_table_elt_t **) ((char *) &r->headers_in + hh->offset);
- if (*ph) {
- ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len);
-
- goto done;
- }
-
- XSRETURN_UNDEF;
-
- multi:
-
- /* Cookie, X-Forwarded-For */
-
- a = (ngx_array_t *) ((char *) &r->headers_in + hh->offset);
-
- n = a->nelts;
-
- if (n == 0) {
- XSRETURN_UNDEF;
- }
-
- ph = a->elts;
-
- if (n == 1) {
- ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len);
-
- goto done;
- }
-
- size = - (ssize_t) (sizeof("; ") - 1);
-
- for (i = 0; i < n; i++) {
- size += ph[i]->value.len + sizeof("; ") - 1;
- }
-
- value = ngx_pnalloc(r->pool, size);
- if (value == NULL) {
- ctx->error = 1;
- croak("ngx_pnalloc() failed");
- }
-
- p = value;
-
- for (i = 0; /* void */ ; i++) {
- p = ngx_copy(p, ph[i]->value.data, ph[i]->value.len);
-
- if (i == n - 1) {
- break;
- }
-
- *p++ = sep; *p++ = ' ';
- }
-
- ngx_http_perl_set_targ(value, size);
-
- goto done;
+ goto found;
}
/* iterate over all headers */
+ sep = ',';
+ ph = &header;
+
part = &r->headers_in.headers.part;
h = part->elts;
@@ -395,12 +339,49 @@ header_in(r, key)
continue;
}
- ngx_http_perl_set_targ(h[i].value.data, h[i].value.len);
+ *ph = &h[i];
+ ph = &h[i].next;
+ }
+
+ *ph = NULL;
+ ph = &header;
+
+ found:
+
+ if (*ph == NULL) {
+ XSRETURN_UNDEF;
+ }
+ if ((*ph)->next == NULL) {
+ ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len);
goto done;
}
- XSRETURN_UNDEF;
+ size = - (ssize_t) (sizeof("; ") - 1);
+
+ for (h = *ph; h; h = h->next) {
+ size += h->value.len + sizeof("; ") - 1;
+ }
+
+ value = ngx_pnalloc(r->pool, size);
+ if (value == NULL) {
+ ctx->error = 1;
+ croak("ngx_pnalloc() failed");
+ }
+
+ p = value;
+
+ for (h = *ph; h; h = h->next) {
+ p = ngx_copy(p, h->value.data, h->value.len);
+
+ if (h->next == NULL) {
+ break;
+ }
+
+ *p++ = sep; *p++ = ' ';
+ }
+
+ ngx_http_perl_set_targ(value, size);
done:
@@ -591,6 +572,7 @@ header_out(r, key, value)
}
header->hash = 1;
+ header->next = NULL;
if (ngx_http_perl_sv2str(aTHX_ r, &header->key, key) != NGX_OK) {
header->hash = 0;