Skip to content

bug: ETag and Last-Modified headers are not preserved when response is Brotli-compressed #12707

@joshdcu

Description

@joshdcu

Current Behavior

The ETag and Last-Modified headers are cleared when the response is compressed by the Brotli plugin:

core.response.clear_header_as_body_modified()
core.response.add_header("Content-Encoding", "br")

function _M.clear_header_as_body_modified()
ngx.header.content_length = nil
-- in case of upstream content is compressed content
ngx.header.content_encoding = nil
-- clear cache identifier
ngx.header.last_modified = nil
ngx.header.etag = nil
end

Expected Behavior

The ETag and Last-Modified headers from the upstream server should be preserved even though the response is Brotli-compressed. Clearing these headers is not required because if the source content has not changed, then the compressed content would not change either and the browser can avoid requesting the unchanged content from the server again.

The APISIX gzip plugin appears not to clear these headers. This also indicates that clearing these headers is not required.

Error Logs

No response

Steps to Reproduce

  1. Build an APISIX image with the Brotli shared libraries as mentioned in the documentation.
  2. Prepare an upstream server that returns a response with the ETag and Last-Modified headers.
  3. Create an APISIX route to the upstream server that enables the Brotli plugin.
  4. Make a request to the upstream server via APISIX with the Accept-Encoding header set to br and observe that the ETag and Last-Modified headers are removed.

Environment

  • APISIX version (run apisix version): 3.9.1
  • Operating system (run uname -a): Linux
  • OpenResty / Nginx version (run openresty -V or nginx -V): nginx version: openresty/1.25.3.1
  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info): Not relevant
  • APISIX Dashboard version, if relevant: Not relevant
  • Plugin runner version, for issues related to plugin runners: Not relevant
  • LuaRocks version, for installation issues (run luarocks --version): Not relevant

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingplugin

    Type

    No type

    Projects

    Status

    📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions