Description
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.