From 08a73b4aadebd9405ac52ec1f6eef5ca1fe8c11a Mon Sep 17 00:00:00 2001 From: Maxim Dounin Date: Mon, 18 Feb 2013 13:50:52 +0000 Subject: Proxy: support for connection upgrade (101 Switching Protocols). This allows to proxy WebSockets by using configuration like this: location /chat/ { proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } Connection upgrade is allowed as long as it was requested by a client via the Upgrade request header. --- src/http/modules/ngx_http_proxy_module.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/http/modules/ngx_http_proxy_module.c') diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c index ce47a9e34..a623adc34 100644 --- a/src/http/modules/ngx_http_proxy_module.c +++ b/src/http/modules/ngx_http_proxy_module.c @@ -1474,6 +1474,14 @@ ngx_http_proxy_process_header(ngx_http_request_t *r) u->keepalive = !u->headers_in.connection_close; } + if (u->headers_in.status_n == NGX_HTTP_SWITCHING_PROTOCOLS) { + u->keepalive = 0; + + if (r->headers_in.upgrade) { + u->upgrade = 1; + } + } + return NGX_OK; } -- cgit v1.2.3