Skip to content

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

Open
@ShawnJoe95

Description

@ShawnJoe95

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions