comparison src/http/ngx_http_header_filter_module.c @ 5072:7fa7e60a7f66

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.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 18 Feb 2013 13:50:52 +0000
parents 812c4765c954
children 941c5e3561ed
comparison
equal deleted inserted replaced
5071:e14b49c12a73 5072:7fa7e60a7f66
377 377
378 if (r->chunked) { 378 if (r->chunked) {
379 len += sizeof("Transfer-Encoding: chunked" CRLF) - 1; 379 len += sizeof("Transfer-Encoding: chunked" CRLF) - 1;
380 } 380 }
381 381
382 if (r->keepalive) { 382 if (r->headers_out.status == NGX_HTTP_SWITCHING_PROTOCOLS) {
383 len += sizeof("Connection: upgrade" CRLF) - 1;
384
385 } else if (r->keepalive) {
383 len += sizeof("Connection: keep-alive" CRLF) - 1; 386 len += sizeof("Connection: keep-alive" CRLF) - 1;
384 387
385 /* 388 /*
386 * MSIE and Opera ignore the "Keep-Alive: timeout=<N>" header. 389 * MSIE and Opera ignore the "Keep-Alive: timeout=<N>" header.
387 * MSIE keeps the connection alive for about 60-65 seconds. 390 * MSIE keeps the connection alive for about 60-65 seconds.
546 if (r->chunked) { 549 if (r->chunked) {
547 b->last = ngx_cpymem(b->last, "Transfer-Encoding: chunked" CRLF, 550 b->last = ngx_cpymem(b->last, "Transfer-Encoding: chunked" CRLF,
548 sizeof("Transfer-Encoding: chunked" CRLF) - 1); 551 sizeof("Transfer-Encoding: chunked" CRLF) - 1);
549 } 552 }
550 553
551 if (r->keepalive) { 554 if (r->headers_out.status == NGX_HTTP_SWITCHING_PROTOCOLS) {
555 b->last = ngx_cpymem(b->last, "Connection: upgrade" CRLF,
556 sizeof("Connection: upgrade" CRLF) - 1);
557
558 } else if (r->keepalive) {
552 b->last = ngx_cpymem(b->last, "Connection: keep-alive" CRLF, 559 b->last = ngx_cpymem(b->last, "Connection: keep-alive" CRLF,
553 sizeof("Connection: keep-alive" CRLF) - 1); 560 sizeof("Connection: keep-alive" CRLF) - 1);
554 561
555 if (clcf->keepalive_header) { 562 if (clcf->keepalive_header) {
556 b->last = ngx_sprintf(b->last, "Keep-Alive: timeout=%T" CRLF, 563 b->last = ngx_sprintf(b->last, "Keep-Alive: timeout=%T" CRLF,