Welcome! Log In Create A New Profile

Advanced

[nginx] Perl: combining unknown headers during $r->header_in() lookup.

Sergey Kandaurov
May 30, 2022 06:34PM
details: https://hg.nginx.org/nginx/rev/ca78312db071
branches:
changeset: 8027:ca78312db071
user: Maxim Dounin <mdounin@mdounin.ru>
date: Mon May 30 21:25:38 2022 +0300
description:
Perl: combining unknown headers during $r->header_in() lookup.

diffstat:

src/http/modules/perl/nginx.xs | 84 ++++++++++++++++++++++--------------------
1 files changed, 44 insertions(+), 40 deletions(-)

diffs (116 lines):

diff -r 8b3860b52bb3 -r ca78312db071 src/http/modules/perl/nginx.xs
--- a/src/http/modules/perl/nginx.xs Mon May 30 21:25:36 2022 +0300
+++ b/src/http/modules/perl/nginx.xs Mon May 30 21:25:38 2022 +0300
@@ -272,7 +272,7 @@ header_in(r, key)
ngx_uint_t i, n, hash;
ngx_array_t *a;
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;

@@ -311,47 +311,14 @@ header_in(r, key)

ph = (ngx_table_elt_t **) ((char *) &r->headers_in + hh->offset);

- if (*ph == NULL) {
- XSRETURN_UNDEF;
- }
-
- if ((*ph)->next == NULL) {
- ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len);
-
- goto done;
- }
-
- 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);
-
- goto done;
+ goto found;
}

/* iterate over all headers */

+ sep = ',';
+ ph = &header;
+
part = &r->headers_in.headers.part;
h = part->elts;

@@ -373,12 +340,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:

_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[nginx] Perl: combining unknown headers during $r->header_in() lookup.

Sergey Kandaurov 285 May 30, 2022 06:34PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 47
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready