Mercurial > hg > nginx-quic
comparison src/http/modules/perl/nginx.xs @ 8873:ef6a3a99a81a
Reworked multi headers to use linked lists.
Multi headers are now using linked lists instead of arrays. Notably,
the following fields were changed: r->headers_in.cookies (renamed
to r->headers_in.cookie), r->headers_in.x_forwarded_for,
r->headers_out.cache_control, r->headers_out.link, u->headers_in.cache_control
u->headers_in.cookies (renamed to u->headers_in.set_cookie).
The r->headers_in.cookies and u->headers_in.cookies fields were renamed
to r->headers_in.cookie and u->headers_in.set_cookie to match header names.
The ngx_http_parse_multi_header_lines() and ngx_http_parse_set_cookie_lines()
functions were changed accordingly.
With this change, multi headers are now essentially equivalent to normal
headers, and following changes will further make them equivalent.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 30 May 2022 21:25:33 +0300 |
parents | 56b4fb46ba7d |
children | 8b3860b52bb3 |
comparison
equal
deleted
inserted
replaced
8872:08b3ea81ff5f | 8873:ef6a3a99a81a |
---|---|
300 | 300 |
301 hh = ngx_hash_find(&cmcf->headers_in_hash, hash, lowcase_key, len); | 301 hh = ngx_hash_find(&cmcf->headers_in_hash, hash, lowcase_key, len); |
302 | 302 |
303 if (hh) { | 303 if (hh) { |
304 | 304 |
305 if (hh->offset == offsetof(ngx_http_headers_in_t, cookies)) { | 305 if (hh->offset == offsetof(ngx_http_headers_in_t, cookie)) { |
306 sep = ';'; | 306 sep = ';'; |
307 goto multi; | 307 goto multi; |
308 } | 308 } |
309 #if (NGX_HTTP_X_FORWARDED_FOR) | 309 #if (NGX_HTTP_X_FORWARDED_FOR) |
310 if (hh->offset == offsetof(ngx_http_headers_in_t, x_forwarded_for)) { | 310 if (hh->offset == offsetof(ngx_http_headers_in_t, x_forwarded_for)) { |
325 | 325 |
326 multi: | 326 multi: |
327 | 327 |
328 /* Cookie, X-Forwarded-For */ | 328 /* Cookie, X-Forwarded-For */ |
329 | 329 |
330 a = (ngx_array_t *) ((char *) &r->headers_in + hh->offset); | 330 ph = (ngx_table_elt_t **) ((char *) &r->headers_in + hh->offset); |
331 | 331 |
332 n = a->nelts; | 332 if (*ph == NULL) { |
333 | |
334 if (n == 0) { | |
335 XSRETURN_UNDEF; | 333 XSRETURN_UNDEF; |
336 } | 334 } |
337 | 335 |
338 ph = a->elts; | 336 if ((*ph)->next == NULL) { |
339 | |
340 if (n == 1) { | |
341 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len); | 337 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len); |
342 | 338 |
343 goto done; | 339 goto done; |
344 } | 340 } |
345 | 341 |
346 size = - (ssize_t) (sizeof("; ") - 1); | 342 size = - (ssize_t) (sizeof("; ") - 1); |
347 | 343 |
348 for (i = 0; i < n; i++) { | 344 for (h = *ph; h; h = h->next) { |
349 size += ph[i]->value.len + sizeof("; ") - 1; | 345 size += h->value.len + sizeof("; ") - 1; |
350 } | 346 } |
351 | 347 |
352 value = ngx_pnalloc(r->pool, size); | 348 value = ngx_pnalloc(r->pool, size); |
353 if (value == NULL) { | 349 if (value == NULL) { |
354 ctx->error = 1; | 350 ctx->error = 1; |
355 croak("ngx_pnalloc() failed"); | 351 croak("ngx_pnalloc() failed"); |
356 } | 352 } |
357 | 353 |
358 p = value; | 354 p = value; |
359 | 355 |
360 for (i = 0; /* void */ ; i++) { | 356 for (h = *ph; h; h = h->next) { |
361 p = ngx_copy(p, ph[i]->value.data, ph[i]->value.len); | 357 p = ngx_copy(p, h->value.data, h->value.len); |
362 | 358 |
363 if (i == n - 1) { | 359 if (h->next == NULL) { |
364 break; | 360 break; |
365 } | 361 } |
366 | 362 |
367 *p++ = sep; *p++ = ' '; | 363 *p++ = sep; *p++ = ' '; |
368 } | 364 } |