commit 8ce360e21d972879e0fc29565c6343a100d507fe Author: weiyue Date: Thu Jan 7 12:13:41 2016 +0800 support 'proxy_http_version auto;' diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c index 1a837ae..7835327 100644 --- a/src/http/modules/ngx_http_proxy_module.c +++ b/src/http/modules/ngx_http_proxy_module.c @@ -228,6 +228,7 @@ static ngx_conf_bitmask_t ngx_http_proxy_ssl_protocols[] = { static ngx_conf_enum_t ngx_http_proxy_http_version[] = { { ngx_string("1.0"), NGX_HTTP_VERSION_10 }, { ngx_string("1.1"), NGX_HTTP_VERSION_11 }, + { ngx_string("auto"), 0 }, { ngx_null_string, 0 } }; @@ -1224,9 +1225,19 @@ ngx_http_proxy_create_request(ngx_http_request_t *r) b->last = ngx_cpymem(b->last, ngx_http_proxy_version_11, sizeof(ngx_http_proxy_version_11) - 1); - } else { + } else if (plcf->http_version == NGX_HTTP_VERSION_10) { b->last = ngx_cpymem(b->last, ngx_http_proxy_version, sizeof(ngx_http_proxy_version) - 1); + + } else { + if (r->http_version == NGX_HTTP_VERSION_11) { + b->last = ngx_cpymem(b->last, ngx_http_proxy_version_11, + sizeof(ngx_http_proxy_version_11) - 1); + + } else { + b->last = ngx_cpymem(b->last, ngx_http_proxy_version, + sizeof(ngx_http_proxy_version) - 1); + } } ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); diff --git a/tests/nginx-tests/cases/proxy_http_version_auto.t b/tests/nginx-tests/cases/proxy_http_version_auto.t new file mode 100644 index 0000000..061e7dc --- /dev/null +++ b/tests/nginx-tests/cases/proxy_http_version_auto.t @@ -0,0 +1,70 @@ +#!/usr/bin/perl + + +############################################################################### + +use warnings; +use strict; + +use Test::More; + +BEGIN { use FindBin; chdir($FindBin::Bin); } + +use Socket qw/ CRLF /; + +use lib 'lib'; +use Test::Nginx; + +############################################################################### + +select STDERR; $| = 1; +select STDOUT; $| = 1; + +my $t = Test::Nginx->new()->plan(2); +$t->write_file_expand('nginx.conf', <<'EOF'); + +%%TEST_GLOBALS%% + +daemon off; + +%%TEST_GLOBALS_DSO%% + +events { +} + +http { + %%TEST_GLOBALS_HTTP%% + + proxy_http_version auto; + + server { + listen 127.0.0.1:8080; + server_name localhost; + + location / { + proxy_pass http://127.0.0.1:1970; + } + } + + server { + listen 127.0.0.1:1970; + server_name localhost; + + location / { + echo "$request"; + } + } + +} + +EOF + + +$t->run(); + +############################################################################### + +like(http('GET / HTTP/1.1' . CRLF . 'Host: localhost' . CRLF . 'Connection:close'. CRLF . CRLF), qr!GET / HTTP/1.1!, 'http 1.1'); +like(http('GET / HTTP/1.0' . CRLF . 'Host: localhost' . CRLF . 'Connection:close'. CRLF . CRLF), qr!GET / HTTP/1.0!, 'http 1.0'); + +###############################################################################