Last active
April 13, 2018 12:42
-
-
Save mayorova/4894dbf8a33c4a8ed4e639620076df63 to your computer and use it in GitHub Desktop.
Host header in OpenResty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Test::Nginx::Socket::Lua 'no_plan'; | |
run_tests(); | |
__DATA__ | |
=== TEST 1: failing test | |
--- config | |
resolver 1.1.1.1; | |
location = /t { | |
set $original_host ""; | |
set $backend "ec2-54-87-144-63.compute-1.amazonaws.com"; | |
proxy_pass http://$backend/upstream; | |
proxy_set_header Host $http_host; | |
proxy_set_header Original-Host $original_host; | |
access_by_lua_block { | |
ngx.var.original_host = ngx.var.http_host | |
ngx.req.set_header('Host', ngx.var.backend) | |
} | |
} | |
--- request | |
GET /t | |
--- more_headers | |
Host: original | |
--- error_code: 200 | |
--- response_body_like | |
.*Host: ec2-54-87-144-63.compute-1.amazonaws.com[\r\n]+Original-Host: original.* | |
=== TEST 2: passing test | |
--- config | |
resolver 1.1.1.1; | |
location = /t { | |
set $original_host ""; | |
set $backend "ec2-54-87-144-63.compute-1.amazonaws.com"; | |
proxy_pass http://$backend/upstream; | |
proxy_set_header Host $http_host; | |
proxy_set_header Original-Host $original_host; | |
access_by_lua_block { | |
ngx.var.original_host = ngx.req.get_headers()['Host'] | |
ngx.req.set_header('Host', ngx.var.backend) | |
} | |
} | |
--- request | |
GET /t | |
--- more_headers | |
Host: original | |
--- error_code: 200 | |
--- response_body_like | |
.*Host: ec2-54-87-144-63.compute-1.amazonaws.com[\r\n]+Original-Host: original.* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment