openresty / openresty/headers-more-nginx-module

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

Open
#122 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
1.8k
Forks
236
Avg merge
1h 34m
Merged PRs (30d)
2

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/ngx_http_headers_more_headers_out.c at ngx_http_set_builtin_multi_header, especially the branch around line 376 where Cache-Control is added without an old value. Reproduce the supplied NGINX configuration and curl request, then verify that clearing Cache-Control produces no empty response header while the existing non-empty-header behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.