Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: wip: Set headers in the tail of a list rather than in the head #2182

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 20 additions & 42 deletions src/ngx_http_lua_headers_out.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,62 +319,40 @@ ngx_http_set_builtin_multi_header(ngx_http_request_t *r,

headers = (ngx_table_elt_t **) ((char *) &r->headers_out + hv->offset);

if (hv->no_override) {
for (h = *headers; h; h = h->next) {
if (!h->hash) {
h->value = *value;
h->hash = hv->hash;
return NGX_OK;
}
}

goto create;
}

/* override old values (if any) */

if (*headers) {
for (h = (*headers)->next; h; h = h->next) {
for (h = *headers; h; h = h->next) {
if (!hv->no_override) {
h->hash = 0;
h->value.len = 0;
}
}

h = *headers;

if (h->hash == 0) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no, I'm afraid here h is NULL ptr after last for loop iterate...

// update the last element if possible
h->value = *value;

if (value->len == 0) {
h->hash = 0;

} else {
if (value->len != 0) {
h->hash = hv->hash;
}

return NGX_OK;
}

create:

for (ph = headers; *ph; ph = &(*ph)->next) { /* void */ }
} else {
ho = ngx_list_push(&r->headers_out.headers);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when last element is valid and other elements are not, here will make a new element, right? Does it mean that the invalid elements never be reused in pool? So why not just nullifying the first element next for simplicity?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually when set builtin multi input header, it just nullifying the next pointer.

can we do same thing for output headers?

if (ho == NULL) {
return NGX_ERROR;
}

ho = ngx_list_push(&r->headers_out.headers);
if (ho == NULL) {
return NGX_ERROR;
}
ho->value = *value;

ho->value = *value;
if (value->len == 0) {
ho->hash = 0;

if (value->len == 0) {
ho->hash = 0;
} else {
ho->hash = hv->hash;
}

} else {
ho->hash = hv->hash;
ho->key = hv->key;
ho->next = NULL;
h->next = ho;
}

ho->key = hv->key;
ho->next = NULL;
*ph = ho;

return NGX_OK;
#else
ngx_array_t *pa;
Expand Down