Skip to content

Receive duplicate response header Connection: upgrade #2392

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

Open
outsinre opened this issue Feb 7, 2025 · 2 comments
Open

Receive duplicate response header Connection: upgrade #2392

outsinre opened this issue Feb 7, 2025 · 2 comments

Comments

@outsinre
Copy link

outsinre commented Feb 7, 2025

I want to simulate an HTTP 101 status code as follows.

# nginx.conf

worker_processes  1;
error_log logs/error.log debug;

events {
    worker_connections 1024;
}

http {
    lua_code_cache on;
    lua_package_path 'assets/?.lua;;';

    server {
        server_name www.example.com;
        listen 80;

        default_type text/html;

        access_log logs/access.log combined;

        location / {
            header_filter_by_lua_block {
                ngx.status = ngx.HTTP_SWITCHING_PROTOCOLS
                ngx.header["Connection"] = 'upgrade'
                ngx.header["Upgrade"] = 'foo/1, webscocket,bar/2'
                return ngx.exit(ngx.HTTP_OK)
            }
        }

    }
}

But got duplicate Connection: upgrade header:

root@73c270625dcb:/# curl -i localhost
HTTP/1.1 101 Switching Protocols
Server: openresty/1.25.3.2
Date: Fri, 07 Feb 2025 12:11:28 GMT
Content-Length: 0
Connection: upgrade
Connection: upgrade
Upgrade: foo/1, webscocket,bar/2

curl: (52) Empty reply from server
@oowl
Copy link
Contributor

oowl commented Feb 8, 2025

This is because nginx will default to adding the Connection header https://github.com/nginx/nginx/blob/ecb809305e54ed15be9f620d56b19ff4e4be7db5/src/http/ngx_http_header_filter_module.c#L559 when sending headers, but openresty continues to add another Connection header in header output logic, So we do not need to add connection header again to avoid this unclear situation.

I am not sure if it is necessary to add additional restrictions in the openresty code to avoid this situation? ngx.header["Connection"] = 'upgrade' @zhuizhuhaomeng ?

@outsinre
Copy link
Author

@oowl then this seems to be related to Nginx, not OpenResty. We can bypass the issue by not offering the Connection: upgrade part.

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

2 participants