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

more_clear_headers "Cache-Control"; Generates an empty Cache-Control response header. #122

Open
ShawnJoe95 opened this issue Jul 14, 2021 · 0 comments

Comments

@ShawnJoe95
Copy link

ShawnJoe95 commented Jul 14, 2021

An example that can reproduce this situation:
server {
listen 8848;
server_name test.test.com;
more_clear_headers "Cache-Control";
location ~* / {
echo "test";
}
}
=====Request: curl "127.0.0.1:8848" -H"host:test.test.com" -v
=====Response:
< HTTP/1.1 200 OK
< Server: openresty/1.15.8.1
< Date: Wed, 14 Jul 2021 07:59:15 GMT
< Content-Type: application/octet-stream
< Transfer-Encoding: chunked
< Connection: keep-alive
< Cache-Control:
<
test

The following configuration can resolve this situation:
server {
listen 8848;
server_name test.test.com;
more_set_headers Cache-Control "Anything";
more_clear_headers "Cache-Control";
location ~* / {
echo "test";
}
}
The same request got the following result:
< HTTP/1.1 200 OK
< Server: openresty/1.15.8.1
< Date: Wed, 14 Jul 2021 08:04:05 GMT
< Content-Type: application/octet-stream
< Transfer-Encoding: chunked
< Connection: keep-alive
<
test

==========Problem==========
src/ngx_http_headers_more_headers_out.c, function "ngx_http_set_builtin_multi_header", line 376.

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

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

    ho->value = *value;
    ho->hash = hv->hash;  //The code cause the situation
    ngx_str_set(&ho->key, "Cache-Control");
    *ph = ho;

    return NGX_OK;
}

Set a null value to Cache-Control header when it has no old-value will set the "ho->hash" into "hv->hash" but not zero. Actually it should be zero, is that right?
I change the code like that:

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

Then it works.
I just want to know is a bug or feature. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant