Skip to content

Commit 53a0de6

Browse files
committed
Tests for proxy methods
1 parent c33070e commit 53a0de6

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

t/11-proxy.t

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# vim:set ft= ts=4 sw=4 et:
2+
3+
use Test::Nginx::Socket;
4+
use Cwd qw(cwd);
5+
6+
plan tests => repeat_each() * (blocks() * 5);
7+
8+
my $pwd = cwd();
9+
10+
our $HttpConfig = qq{
11+
lua_package_path "$pwd/lib/?.lua;;";
12+
error_log logs/error.log debug;
13+
};
14+
15+
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
16+
17+
no_long_string();
18+
#no_diff();
19+
20+
run_tests();
21+
22+
__DATA__
23+
=== TEST 1: Proxy GET request and response
24+
--- http_config eval: $::HttpConfig
25+
--- config
26+
location = /a_prx {
27+
rewrite ^(.*)_prx$ $1 break;
28+
content_by_lua '
29+
local http = require "resty.http"
30+
local httpc = http.new()
31+
httpc:connect("127.0.0.1", ngx.var.server_port)
32+
httpc:proxy_response(httpc:proxy_request())
33+
httpc:set_keepalive()
34+
';
35+
}
36+
location = /a {
37+
content_by_lua '
38+
ngx.status = 200
39+
ngx.header["X-Test"] = "foo"
40+
ngx.say("OK")
41+
';
42+
}
43+
--- request
44+
GET /a_prx
45+
--- response_body
46+
OK
47+
--- response_headers
48+
X-Test: foo
49+
--- error_code: 200
50+
--- no_error_log
51+
[error]
52+
[warn]
53+
54+
55+
=== TEST 2: Proxy POST request and response
56+
--- http_config eval: $::HttpConfig
57+
--- config
58+
location = /a_prx {
59+
rewrite ^(.*)_prx$ $1 break;
60+
content_by_lua '
61+
local http = require "resty.http"
62+
local httpc = http.new()
63+
httpc:connect("127.0.0.1", ngx.var.server_port)
64+
httpc:proxy_response(httpc:proxy_request())
65+
httpc:set_keepalive()
66+
';
67+
}
68+
location = /a {
69+
lua_need_request_body on;
70+
content_by_lua '
71+
ngx.status = 404
72+
ngx.header["X-Test"] = "foo"
73+
local args, err = ngx.req.get_post_args()
74+
ngx.say(args["foo"])
75+
ngx.say(args["hello"])
76+
';
77+
}
78+
--- request
79+
POST /a_prx
80+
foo=bar&hello=world
81+
--- response_body
82+
bar
83+
world
84+
--- response_headers
85+
X-Test: foo
86+
--- error_code: 404
87+
--- no_error_log
88+
[error]
89+
[warn]
90+

0 commit comments

Comments
 (0)