Mercurial > hg > nginx
comparison src/http/modules/ngx_http_headers_filter_module.c @ 8024: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 | 6ba68ad8b24c |
children | d26db4f82d7d |
comparison
equal
deleted
inserted
replaced
8023:08b3ea81ff5f | 8024:ef6a3a99a81a |
---|---|
327 char *err; | 327 char *err; |
328 size_t len; | 328 size_t len; |
329 time_t now, expires_time, max_age; | 329 time_t now, expires_time, max_age; |
330 ngx_str_t value; | 330 ngx_str_t value; |
331 ngx_int_t rc; | 331 ngx_int_t rc; |
332 ngx_uint_t i; | 332 ngx_table_elt_t *e, *cc; |
333 ngx_table_elt_t *e, *cc, **ccp; | |
334 ngx_http_expires_t expires; | 333 ngx_http_expires_t expires; |
335 | 334 |
336 expires = conf->expires; | 335 expires = conf->expires; |
337 expires_time = conf->expires_time; | 336 expires_time = conf->expires_time; |
338 | 337 |
369 } | 368 } |
370 | 369 |
371 len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT"); | 370 len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT"); |
372 e->value.len = len - 1; | 371 e->value.len = len - 1; |
373 | 372 |
374 ccp = r->headers_out.cache_control.elts; | 373 cc = r->headers_out.cache_control; |
375 | 374 |
376 if (ccp == NULL) { | 375 if (cc == NULL) { |
377 | |
378 if (ngx_array_init(&r->headers_out.cache_control, r->pool, | |
379 1, sizeof(ngx_table_elt_t *)) | |
380 != NGX_OK) | |
381 { | |
382 return NGX_ERROR; | |
383 } | |
384 | 376 |
385 cc = ngx_list_push(&r->headers_out.headers); | 377 cc = ngx_list_push(&r->headers_out.headers); |
386 if (cc == NULL) { | 378 if (cc == NULL) { |
387 return NGX_ERROR; | 379 return NGX_ERROR; |
388 } | 380 } |
389 | 381 |
382 r->headers_out.cache_control = cc; | |
383 cc->next = NULL; | |
384 | |
390 cc->hash = 1; | 385 cc->hash = 1; |
391 ngx_str_set(&cc->key, "Cache-Control"); | 386 ngx_str_set(&cc->key, "Cache-Control"); |
392 | 387 |
393 ccp = ngx_array_push(&r->headers_out.cache_control); | |
394 if (ccp == NULL) { | |
395 return NGX_ERROR; | |
396 } | |
397 | |
398 *ccp = cc; | |
399 | |
400 } else { | 388 } else { |
401 for (i = 1; i < r->headers_out.cache_control.nelts; i++) { | 389 for (cc = cc->next; cc; cc = cc->next) { |
402 ccp[i]->hash = 0; | 390 cc->hash = 0; |
403 } | 391 } |
404 | 392 |
405 cc = ccp[0]; | 393 cc = r->headers_out.cache_control; |
394 cc->next = NULL; | |
406 } | 395 } |
407 | 396 |
408 if (expires == NGX_HTTP_EXPIRES_EPOCH) { | 397 if (expires == NGX_HTTP_EXPIRES_EPOCH) { |
409 e->value.data = (u_char *) "Thu, 01 Jan 1970 00:00:01 GMT"; | 398 e->value.data = (u_char *) "Thu, 01 Jan 1970 00:00:01 GMT"; |
410 ngx_str_set(&cc->value, "no-cache"); | 399 ngx_str_set(&cc->value, "no-cache"); |
562 | 551 |
563 static ngx_int_t | 552 static ngx_int_t |
564 ngx_http_add_multi_header_lines(ngx_http_request_t *r, | 553 ngx_http_add_multi_header_lines(ngx_http_request_t *r, |
565 ngx_http_header_val_t *hv, ngx_str_t *value) | 554 ngx_http_header_val_t *hv, ngx_str_t *value) |
566 { | 555 { |
567 ngx_array_t *pa; | |
568 ngx_table_elt_t *h, **ph; | 556 ngx_table_elt_t *h, **ph; |
569 | 557 |
570 if (value->len == 0) { | 558 if (value->len == 0) { |
571 return NGX_OK; | 559 return NGX_OK; |
572 } | |
573 | |
574 pa = (ngx_array_t *) ((char *) &r->headers_out + hv->offset); | |
575 | |
576 if (pa->elts == NULL) { | |
577 if (ngx_array_init(pa, r->pool, 1, sizeof(ngx_table_elt_t *)) != NGX_OK) | |
578 { | |
579 return NGX_ERROR; | |
580 } | |
581 } | 560 } |
582 | 561 |
583 h = ngx_list_push(&r->headers_out.headers); | 562 h = ngx_list_push(&r->headers_out.headers); |
584 if (h == NULL) { | 563 if (h == NULL) { |
585 return NGX_ERROR; | 564 return NGX_ERROR; |
587 | 566 |
588 h->hash = 1; | 567 h->hash = 1; |
589 h->key = hv->key; | 568 h->key = hv->key; |
590 h->value = *value; | 569 h->value = *value; |
591 | 570 |
592 ph = ngx_array_push(pa); | 571 ph = (ngx_table_elt_t **) ((char *) &r->headers_out + hv->offset); |
593 if (ph == NULL) { | 572 |
594 return NGX_ERROR; | 573 while (*ph) { ph = &(*ph)->next; } |
595 } | |
596 | 574 |
597 *ph = h; | 575 *ph = h; |
576 h->next = NULL; | |
598 | 577 |
599 return NGX_OK; | 578 return NGX_OK; |
600 } | 579 } |
601 | 580 |
602 | 581 |