diff --git a/nginx.tmpl b/nginx.tmpl index 9eb9520..c857d7e 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -19,11 +19,18 @@ # If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the # scheme used to connect to this server -map $http_x_forwarded_proto $proxy_x_forwarded_proto { +map $http_x_forwarded_proto $default_forwarded_proto { default $http_x_forwarded_proto; '' $scheme; } +# If we received a HTTP-CloudFront-Forwarded-Proto, pass it through; otherwise, +# pass along the original value. +map $http_cloudfront_forwarded_proto $proxy_x_forwarded_proto { + default $http_cloudfront_forwarded_proto; + '' $default_forwarded_proto; +} + # If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any # Connection header that may have been passed to this server map $http_upgrade $proxy_connection { diff --git a/test/default-host.bats b/test/default-host.bats index acdffc6..065532c 100644 --- a/test/default-host.bats +++ b/test/default-host.bats @@ -26,6 +26,14 @@ function setup { # THEN querying the proxy with any other Host header → 200 run curl_container $SUT_CONTAINER / --head --header "Host: something.I.just.made.up" assert_output -l 0 $'HTTP/1.1 200 OK\r' + + # THEN querying the proxy with X-Forwarded-Proto → 200 + run curl_container $SUT_CONTAINER / --head --header "X-Forwarded-Proto: https" + assert_output -l 0 $'HTTP/1.1 200 OK\r' + + # THEN querying the proxy with HTTP-CloudFront-Forwarded-Proto → 200 + run curl_container $SUT_CONTAINER / --head --header "HTTP-CloudFront-Forwarded-Proto: https" + assert_output -l 0 $'HTTP/1.1 200 OK\r' } @test "[$TEST_FILE] stop all bats containers" {