mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
Remove unused test files and certificates from lua-resty-http
This commit is contained in:
parent
ef98a5ae5e
commit
ff1adf0230
27 changed files with 0 additions and 5449 deletions
433
src/deps/src/lua-resty-http/t/01-basic.t
vendored
433
src/deps/src/lua-resty-http/t/01-basic.t
vendored
|
|
@ -1,433 +0,0 @@
|
|||
use Test::Nginx::Socket 'no_plan';
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
}
|
||||
};
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
=== TEST 1: Simple default get.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect{
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
}
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b"
|
||||
}
|
||||
|
||||
ngx.status = res.status
|
||||
ngx.print(res:read_body())
|
||||
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
echo "OK";
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
OK
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 2: HTTP 1.0
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect{
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
}
|
||||
|
||||
local res, err = httpc:request{
|
||||
version = 1.0,
|
||||
path = "/b"
|
||||
}
|
||||
|
||||
ngx.status = res.status
|
||||
ngx.print(res:read_body())
|
||||
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
echo "OK";
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
OK
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 3: Status code and reason phrase
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
local ok, err = httpc:connect{
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
}
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b"
|
||||
}
|
||||
|
||||
ngx.status = res.status
|
||||
ngx.say(res.reason)
|
||||
ngx.print(res:read_body())
|
||||
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.status = 404
|
||||
ngx.say("OK")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
Not Found
|
||||
OK
|
||||
--- error_code: 404
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 4: Response headers
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect{
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
}
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b"
|
||||
}
|
||||
|
||||
ngx.status = res.status
|
||||
ngx.say(res.headers["X-Test"])
|
||||
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.header["X-Test"] = "x-value"
|
||||
ngx.say("OK")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
x-value
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 5: Query
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect{
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
}
|
||||
|
||||
local res, err = httpc:request{
|
||||
query = {
|
||||
a = 1,
|
||||
b = 2,
|
||||
},
|
||||
path = "/b"
|
||||
}
|
||||
|
||||
ngx.status = res.status
|
||||
|
||||
for k,v in pairs(res.headers) do
|
||||
ngx.header[k] = v
|
||||
end
|
||||
|
||||
ngx.print(res:read_body())
|
||||
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
for k,v in pairs(ngx.req.get_uri_args()) do
|
||||
ngx.header["X-Header-" .. string.upper(k)] = v
|
||||
end
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_headers
|
||||
X-Header-A: 1
|
||||
X-Header-B: 2
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 7: HEAD has no body.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect{
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
}
|
||||
|
||||
local res, err = httpc:request{
|
||||
method = "HEAD",
|
||||
path = "/b"
|
||||
}
|
||||
|
||||
local body = res:read_body()
|
||||
|
||||
if body then
|
||||
ngx.print(body)
|
||||
end
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
echo "OK";
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 8: Errors when not initialized
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
|
||||
local res, err = http:connect{
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
}
|
||||
if not res then ngx.say(err) end
|
||||
|
||||
local res, err = http:set_timeout(500)
|
||||
if not res then ngx.say(err) end
|
||||
|
||||
local res, err = http:set_keepalive()
|
||||
if not res then ngx.say(err) end
|
||||
|
||||
local res, err = http:get_reused_times()
|
||||
if not res then ngx.say(err) end
|
||||
|
||||
local res, err = http:close()
|
||||
if not res then ngx.say(err) end
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
not initialized
|
||||
not initialized
|
||||
not initialized
|
||||
not initialized
|
||||
not initialized
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 12: Allow empty HTTP header values (RFC7230)
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local httpc = require("resty.http").new()
|
||||
|
||||
-- Create a TCP connection and return an raw HTTP-response because
|
||||
-- there is no way to set an empty header value in nginx.
|
||||
assert(httpc:connect{
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = 12345,
|
||||
}, "connect should return positively")
|
||||
|
||||
local res = httpc:request({ path = "/b" })
|
||||
if res.headers["X-Header-Empty"] == "" then
|
||||
ngx.say("Empty")
|
||||
end
|
||||
ngx.say(res.headers["X-Header-Test"])
|
||||
ngx.print(res:read_body())
|
||||
}
|
||||
}
|
||||
--- tcp_listen: 12345
|
||||
--- tcp_reply
|
||||
HTTP/1.0 200 OK
|
||||
Date: Mon, 23 Jul 2018 13:00:00 GMT
|
||||
X-Header-Empty:
|
||||
X-Header-Test: Test
|
||||
Server: OpenResty
|
||||
|
||||
OK
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
Empty
|
||||
Test
|
||||
OK
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
=== TEST 13: Should return error on invalid HTTP version in response status line
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
local res, err = httpc:request_uri("http://127.0.0.1:12345")
|
||||
|
||||
assert(err == "couldn't parse HTTP version from response status line: TEAPOT/1.1 OMG")
|
||||
}
|
||||
}
|
||||
--- tcp_listen: 12345
|
||||
--- tcp_reply
|
||||
TEAPOT/1.1 OMG
|
||||
Server: Teapot
|
||||
|
||||
OK
|
||||
--- request
|
||||
GET /a
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
=== TEST 14: Should return error on invalid status code in response status line
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
local res, err = httpc:request_uri("http://127.0.0.1:12345")
|
||||
|
||||
assert(err == "couldn't parse status code from response status line: HTTP/1.1 OMG")
|
||||
}
|
||||
}
|
||||
--- tcp_listen: 12345
|
||||
--- tcp_reply
|
||||
HTTP/1.1 OMG
|
||||
Server: Teapot
|
||||
|
||||
OK
|
||||
--- request
|
||||
GET /a
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
|
||||
=== TEST 14: Empty query
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect{
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
}
|
||||
|
||||
local res, err = httpc:request{
|
||||
query = {},
|
||||
path = "/b"
|
||||
}
|
||||
|
||||
ngx.status = res.status
|
||||
|
||||
ngx.print(ngx.header.test)
|
||||
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.header.test = ngx.var.request_uri
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_headers
|
||||
/b
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
324
src/deps/src/lua-resty-http/t/02-chunked.t
vendored
324
src/deps/src/lua-resty-http/t/02-chunked.t
vendored
|
|
@ -1,324 +0,0 @@
|
|||
use Test::Nginx::Socket 'no_plan';
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
}
|
||||
};
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
=== TEST 1: Non chunked.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b"
|
||||
}
|
||||
|
||||
local body = res:read_body()
|
||||
|
||||
ngx.say(#body)
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
chunked_transfer_encoding off;
|
||||
content_by_lua '
|
||||
local len = 32768
|
||||
local t = {}
|
||||
for i=1,len do
|
||||
t[i] = 0
|
||||
end
|
||||
ngx.print(table.concat(t))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
32768
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 2: Chunked. The number of chunks received when no max size is given proves the response was in fact chunked.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b"
|
||||
}
|
||||
|
||||
local chunks = {}
|
||||
local c = 1
|
||||
repeat
|
||||
local chunk, err = res.body_reader()
|
||||
if chunk then
|
||||
chunks[c] = chunk
|
||||
c = c + 1
|
||||
end
|
||||
until not chunk
|
||||
|
||||
local body = table.concat(chunks)
|
||||
|
||||
ngx.say(#body)
|
||||
ngx.say(#chunks)
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
local len = 32768
|
||||
local t = {}
|
||||
for i=1,len do
|
||||
t[i] = 0
|
||||
end
|
||||
ngx.print(table.concat(t))
|
||||
local len = 32768
|
||||
local t = {}
|
||||
for i=1,len do
|
||||
t[i] = 0
|
||||
end
|
||||
ngx.print(table.concat(t))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
65536
|
||||
2
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 3: Chunked using read_body method.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b"
|
||||
}
|
||||
|
||||
local body = res:read_body()
|
||||
|
||||
ngx.say(#body)
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
local len = 32768
|
||||
local t = {}
|
||||
for i=1,len do
|
||||
t[i] = 0
|
||||
end
|
||||
ngx.print(table.concat(t))
|
||||
local len = 32768
|
||||
local t = {}
|
||||
for i=1,len do
|
||||
t[i] = 0
|
||||
end
|
||||
ngx.print(table.concat(t))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
65536
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 4: Chunked. multiple-headers, mixed case
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b"
|
||||
}
|
||||
|
||||
local chunks = {}
|
||||
local c = 1
|
||||
repeat
|
||||
local chunk, err = res.body_reader()
|
||||
if chunk then
|
||||
chunks[c] = chunk
|
||||
c = c + 1
|
||||
end
|
||||
until not chunk
|
||||
|
||||
local body = table.concat(chunks)
|
||||
|
||||
ngx.say(#body)
|
||||
ngx.say(#chunks)
|
||||
ngx.say(type(res.headers["Transfer-Encoding"]))
|
||||
httpc:close()
|
||||
}
|
||||
}
|
||||
location = /b {
|
||||
header_filter_by_lua_block {
|
||||
ngx.header["Transfer-Encoding"] = {"chUnked", "CHunked"}
|
||||
}
|
||||
content_by_lua_block {
|
||||
local len = 32768
|
||||
local t = {}
|
||||
for i=1,len do
|
||||
t[i] = 0
|
||||
end
|
||||
ngx.print(table.concat(t))
|
||||
local len = 32768
|
||||
local t = {}
|
||||
for i=1,len do
|
||||
t[i] = 0
|
||||
end
|
||||
ngx.print(table.concat(t))
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
65536
|
||||
2
|
||||
table
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 5: transfer_encoding_is_chunked utility.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local http_headers = require("resty.http_headers")
|
||||
local http = require("resty.http")
|
||||
|
||||
local headers = http_headers:new()
|
||||
assert(http.transfer_encoding_is_chunked(headers) == false,
|
||||
"empty headers should return false")
|
||||
|
||||
headers["Transfer-Encoding"] = "chunked"
|
||||
assert(http.transfer_encoding_is_chunked(headers) == true,
|
||||
"te set to `chunked` should return true`")
|
||||
|
||||
headers["Transfer-Encoding"] = " ChuNkEd "
|
||||
assert(http.transfer_encoding_is_chunked(headers) == true,
|
||||
"te set to ` ChuNkEd ` should return true`")
|
||||
|
||||
headers["Transfer-Encoding"] = { "chunked", " ChuNkEd " }
|
||||
assert(http.transfer_encoding_is_chunked(headers) == true,
|
||||
"te set to table values containing `chunked` should return true`")
|
||||
|
||||
headers["Transfer-Encoding"] = "chunked"
|
||||
headers["Content-Length"] = 10
|
||||
assert(http.transfer_encoding_is_chunked(headers) == true,
|
||||
"transfer encoding should override content-length`")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 6: Don't send Content-Length if Transfer-Encoding is specified
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local httpc = require("resty.http").new()
|
||||
local yield = coroutine.yield
|
||||
|
||||
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/b"
|
||||
|
||||
local res, err = assert(httpc:request_uri(uri, {
|
||||
body = coroutine.wrap(function()
|
||||
yield("3\r\n")
|
||||
yield("foo\r\n")
|
||||
|
||||
yield("3\r\n")
|
||||
yield("bar\r\n")
|
||||
|
||||
yield("0\r\n")
|
||||
yield("\r\n")
|
||||
end),
|
||||
headers = {
|
||||
["Transfer-Encoding"] = "chunked",
|
||||
["Content-Length"] = 42,
|
||||
},
|
||||
}))
|
||||
|
||||
ngx.say(res.body)
|
||||
}
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua_block {
|
||||
ngx.req.read_body()
|
||||
ngx.say(ngx.req.get_headers()["Content-Length"])
|
||||
ngx.print(ngx.req.get_body_data())
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
nil
|
||||
foobar
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
509
src/deps/src/lua-resty-http/t/03-requestbody.t
vendored
509
src/deps/src/lua-resty-http/t/03-requestbody.t
vendored
|
|
@ -1,509 +0,0 @@
|
|||
use Test::Nginx::Socket 'no_plan';
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
}
|
||||
};
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
=== TEST 1: POST form-urlencoded
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
body = "a=1&b=2&c=3",
|
||||
path = "/b",
|
||||
headers = {
|
||||
["Content-Type"] = "application/x-www-form-urlencoded",
|
||||
}
|
||||
}
|
||||
|
||||
ngx.say(res:read_body())
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.req.read_body()
|
||||
local args = ngx.req.get_post_args()
|
||||
ngx.say("a: ", args.a)
|
||||
ngx.say("b: ", args.b)
|
||||
ngx.print("c: ", args.c)
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
a: 1
|
||||
b: 2
|
||||
c: 3
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 2: POST form-urlencoded 1.0
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
method = "POST",
|
||||
body = "a=1&b=2&c=3",
|
||||
path = "/b",
|
||||
headers = {
|
||||
["Content-Type"] = "application/x-www-form-urlencoded",
|
||||
},
|
||||
version = 1.0,
|
||||
}
|
||||
|
||||
ngx.say(res:read_body())
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.req.read_body()
|
||||
local args = ngx.req.get_post_args()
|
||||
ngx.say(ngx.req.get_method())
|
||||
ngx.say("a: ", args.a)
|
||||
ngx.say("b: ", args.b)
|
||||
ngx.print("c: ", args.c)
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
POST
|
||||
a: 1
|
||||
b: 2
|
||||
c: 3
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 3: 100 Continue does not end requset
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
body = "a=1&b=2&c=3",
|
||||
path = "/b",
|
||||
headers = {
|
||||
["Expect"] = "100-continue",
|
||||
["Content-Type"] = "application/x-www-form-urlencoded",
|
||||
}
|
||||
}
|
||||
ngx.say(res.status)
|
||||
ngx.say(res:read_body())
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.req.read_body()
|
||||
local args = ngx.req.get_post_args()
|
||||
ngx.say("a: ", args.a)
|
||||
ngx.say("b: ", args.b)
|
||||
ngx.print("c: ", args.c)
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
200
|
||||
a: 1
|
||||
b: 2
|
||||
c: 3
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
=== TEST 4: Return non-100 status to user
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b",
|
||||
headers = {
|
||||
["Expect"] = "100-continue",
|
||||
["Content-Type"] = "application/x-www-form-urlencoded",
|
||||
}
|
||||
}
|
||||
if not res then
|
||||
ngx.say(err)
|
||||
end
|
||||
ngx.say(res.status)
|
||||
ngx.say(res:read_body())
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
return 417 "Expectation Failed";
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
417
|
||||
Expectation Failed
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 5: Return 100 Continue with headers
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
body = "a=1&b=2&c=3",
|
||||
path = "/b",
|
||||
headers = {
|
||||
["Expect"] = "100-continue",
|
||||
["Content-Type"] = "application/x-www-form-urlencoded",
|
||||
}
|
||||
}
|
||||
|
||||
if not res then
|
||||
ngx.log(ngx.ERR, "httpc:request failed: ", err)
|
||||
end
|
||||
|
||||
ngx.say(res.status)
|
||||
ngx.say(res:read_body())
|
||||
httpc:close()
|
||||
}
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua_block {
|
||||
local len = ngx.req.get_headers()["Content-Length"]
|
||||
|
||||
local sock, err = ngx.req.socket(true)
|
||||
if not sock then
|
||||
ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
-- with additional header
|
||||
local ok, err = sock:send("HTTP/1.1 100 Continue\r\nConnection: keep-alive\r\n\r\n")
|
||||
if not ok then
|
||||
ngx.log(ngx.ERR, "failed to send 100 response: ", err)
|
||||
end
|
||||
|
||||
local data, err = sock:receive(len)
|
||||
if not data then
|
||||
ngx.log(ngx.ERR, "failed to receive: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local ok, err = sock:send("HTTP/1.1 200 OK\r\n" ..
|
||||
"Content-Length: " .. len .. "\r\n" ..
|
||||
"Content-Type: application/x-www-form-urlencoded\r\n\r\n" ..
|
||||
data)
|
||||
if not ok then
|
||||
ngx.log(ngx.ERR, "failed to send 200 response: ", err)
|
||||
return
|
||||
end
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
200
|
||||
a=1&b=2&c=3
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 6: Return 100 Continue without headers
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
body = "a=1&b=2&c=3",
|
||||
path = "/b",
|
||||
headers = {
|
||||
["Expect"] = "100-continue",
|
||||
["Content-Type"] = "application/x-www-form-urlencoded",
|
||||
}
|
||||
}
|
||||
|
||||
if not res then
|
||||
ngx.log(ngx.ERR, "httpc:request failed: ", err)
|
||||
end
|
||||
|
||||
ngx.say(res.status)
|
||||
ngx.say(res:read_body())
|
||||
httpc:close()
|
||||
}
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua_block {
|
||||
local len = ngx.req.get_headers()["Content-Length"]
|
||||
|
||||
local sock, err = ngx.req.socket(true)
|
||||
if not sock then
|
||||
ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
-- without additional headers
|
||||
local ok, err = sock:send("HTTP/1.1 100 Continue\r\n\r\n")
|
||||
if not ok then
|
||||
ngx.log(ngx.ERR, "failed to send 100 response: ", err)
|
||||
end
|
||||
|
||||
local data, err = sock:receive(len)
|
||||
if not data then
|
||||
ngx.log(ngx.ERR, "failed to receive: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local ok, err = sock:send("HTTP/1.1 200 OK\r\n" ..
|
||||
"Content-Length: " .. len .. "\r\n" ..
|
||||
"Content-Type: application/x-www-form-urlencoded\r\n\r\n" ..
|
||||
data)
|
||||
if not ok then
|
||||
ngx.log(ngx.ERR, "failed to send 200 response: ", err)
|
||||
return
|
||||
end
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
200
|
||||
a=1&b=2&c=3
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 7: Non string request bodies are converted with correct length
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local httpc = require("resty.http").new()
|
||||
|
||||
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/b"
|
||||
|
||||
for _, body in ipairs({ 12345,
|
||||
true,
|
||||
"string",
|
||||
{ "tab", "le" },
|
||||
{ "mix", 123, "ed", "tab", "le" } }) do
|
||||
|
||||
local res, err = assert(httpc:request_uri(uri, {
|
||||
body = body,
|
||||
}))
|
||||
|
||||
ngx.say(res.body)
|
||||
end
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.req.read_body()
|
||||
ngx.print(ngx.req.get_body_data())
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
12345
|
||||
true
|
||||
string
|
||||
table
|
||||
mix123edtable
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 8: Request body as iterator
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local httpc = require("resty.http").new()
|
||||
|
||||
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/b"
|
||||
|
||||
local res, err = assert(httpc:request_uri(uri, {
|
||||
body = coroutine.wrap(function()
|
||||
coroutine.yield("foo")
|
||||
coroutine.yield("bar")
|
||||
end),
|
||||
headers = {
|
||||
["Content-Length"] = 6
|
||||
}
|
||||
}))
|
||||
|
||||
ngx.say(res.body)
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.req.read_body()
|
||||
ngx.print(ngx.req.get_body_data())
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
foobar
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 9: Request body as iterator, errors with missing length
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local httpc = require("resty.http").new()
|
||||
|
||||
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/b"
|
||||
|
||||
local res, err = httpc:request_uri(uri, {
|
||||
body = coroutine.wrap(function()
|
||||
coroutine.yield("foo")
|
||||
coroutine.yield("bar")
|
||||
end),
|
||||
})
|
||||
|
||||
assert(not res)
|
||||
ngx.say(err)
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.req.read_body()
|
||||
ngx.print(ngx.req.get_body_data())
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
Request body is a function but a length or chunked encoding is not specified
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 10: Request body as iterator with chunked encoding
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local httpc = require("resty.http").new()
|
||||
local yield = coroutine.yield
|
||||
|
||||
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/b"
|
||||
|
||||
local res, err = assert(httpc:request_uri(uri, {
|
||||
body = coroutine.wrap(function()
|
||||
yield("3\r\n")
|
||||
yield("foo\r\n")
|
||||
|
||||
yield("3\r\n")
|
||||
yield("bar\r\n")
|
||||
|
||||
yield("0\r\n")
|
||||
yield("\r\n")
|
||||
end),
|
||||
headers = {
|
||||
["Transfer-Encoding"] = "chunked"
|
||||
}
|
||||
}))
|
||||
|
||||
ngx.say(res.body)
|
||||
}
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.req.read_body()
|
||||
ngx.print(ngx.req.get_body_data())
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
foobar
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
162
src/deps/src/lua-resty-http/t/04-trailers.t
vendored
162
src/deps/src/lua-resty-http/t/04-trailers.t
vendored
|
|
@ -1,162 +0,0 @@
|
|||
use Test::Nginx::Socket 'no_plan';
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
}
|
||||
};
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
=== TEST 1: Trailers. Check Content-MD5 generated after the body is sent matches up.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b",
|
||||
headers = {
|
||||
["TE"] = "trailers",
|
||||
}
|
||||
}
|
||||
|
||||
local body = res:read_body()
|
||||
local hash = ngx.md5(body)
|
||||
res:read_trailers()
|
||||
|
||||
if res.headers["Content-MD5"] == hash then
|
||||
ngx.say("OK")
|
||||
else
|
||||
ngx.say(res.headers["Content-MD5"])
|
||||
end
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
-- We use the raw socket to compose a response, since OpenResty
|
||||
-- doesnt support trailers natively.
|
||||
|
||||
ngx.req.read_body()
|
||||
local sock, err = ngx.req.socket(true)
|
||||
if not sock then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
local res = {}
|
||||
table.insert(res, "HTTP/1.1 200 OK")
|
||||
table.insert(res, "Date: " .. ngx.http_time(ngx.time()))
|
||||
table.insert(res, "Transfer-Encoding: chunked")
|
||||
table.insert(res, "Trailer: Content-MD5")
|
||||
table.insert(res, "")
|
||||
|
||||
local body = "Hello, World"
|
||||
|
||||
table.insert(res, string.format("%x", #body))
|
||||
table.insert(res, body)
|
||||
table.insert(res, "0")
|
||||
table.insert(res, "")
|
||||
|
||||
table.insert(res, "Content-MD5: " .. ngx.md5(body))
|
||||
|
||||
table.insert(res, "")
|
||||
table.insert(res, "")
|
||||
sock:send(table.concat(res, "\\r\\n"))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
OK
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 2: Advertised trailer does not exist, handled gracefully.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b",
|
||||
headers = {
|
||||
["TE"] = "trailers",
|
||||
}
|
||||
}
|
||||
|
||||
local body = res:read_body()
|
||||
local hash = ngx.md5(body)
|
||||
res:read_trailers()
|
||||
|
||||
ngx.say("OK")
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
-- We use the raw socket to compose a response, since OpenResty
|
||||
-- doesnt support trailers natively.
|
||||
|
||||
ngx.req.read_body()
|
||||
local sock, err = ngx.req.socket(true)
|
||||
if not sock then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
local res = {}
|
||||
table.insert(res, "HTTP/1.1 200 OK")
|
||||
table.insert(res, "Date: " .. ngx.http_time(ngx.time()))
|
||||
table.insert(res, "Transfer-Encoding: chunked")
|
||||
table.insert(res, "Trailer: Content-MD5")
|
||||
table.insert(res, "")
|
||||
|
||||
local body = "Hello, World"
|
||||
|
||||
table.insert(res, string.format("%x", #body))
|
||||
table.insert(res, body)
|
||||
table.insert(res, "0")
|
||||
|
||||
table.insert(res, "")
|
||||
table.insert(res, "")
|
||||
sock:send(table.concat(res, "\\r\\n"))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
OK
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
607
src/deps/src/lua-resty-http/t/05-stream.t
vendored
607
src/deps/src/lua-resty-http/t/05-stream.t
vendored
|
|
@ -1,607 +0,0 @@
|
|||
use Test::Nginx::Socket 'no_plan';
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
}
|
||||
};
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
=== TEST 1: Chunked streaming body reader returns the right content length.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b",
|
||||
}
|
||||
|
||||
local chunks = {}
|
||||
repeat
|
||||
local chunk = res.body_reader()
|
||||
if chunk then
|
||||
table.insert(chunks, chunk)
|
||||
end
|
||||
until not chunk
|
||||
|
||||
local body = table.concat(chunks)
|
||||
ngx.say(#body)
|
||||
ngx.say(res.headers["Transfer-Encoding"])
|
||||
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
local len = 32768
|
||||
local t = {}
|
||||
for i=1,len do
|
||||
t[i] = 0
|
||||
end
|
||||
ngx.print(table.concat(t))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
32768
|
||||
chunked
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 2: Non-Chunked streaming body reader returns the right content length.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b",
|
||||
}
|
||||
|
||||
local chunks = {}
|
||||
repeat
|
||||
local chunk = res.body_reader()
|
||||
if chunk then
|
||||
table.insert(chunks, chunk)
|
||||
end
|
||||
until not chunk
|
||||
|
||||
local body = table.concat(chunks)
|
||||
ngx.say(#body)
|
||||
ngx.say(res.headers["Transfer-Encoding"])
|
||||
ngx.say(#chunks)
|
||||
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
chunked_transfer_encoding off;
|
||||
content_by_lua '
|
||||
local len = 32768
|
||||
local t = {}
|
||||
for i=1,len do
|
||||
t[i] = 0
|
||||
end
|
||||
ngx.print(table.concat(t))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
32768
|
||||
nil
|
||||
1
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 2b: Non-Chunked streaming body reader, buffer size becomes nil
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b",
|
||||
}
|
||||
|
||||
local chunks = {}
|
||||
local buffer_size = 16384
|
||||
repeat
|
||||
local chunk = res.body_reader(buffer_size)
|
||||
if chunk then
|
||||
table.insert(chunks, chunk)
|
||||
end
|
||||
|
||||
buffer_size = nil
|
||||
until not chunk
|
||||
|
||||
local body = table.concat(chunks)
|
||||
ngx.say(res.headers["Transfer-Encoding"])
|
||||
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
chunked_transfer_encoding off;
|
||||
content_by_lua '
|
||||
local len = 32768
|
||||
local t = {}
|
||||
for i=1,len do
|
||||
t[i] = 0
|
||||
end
|
||||
ngx.print(table.concat(t))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
nil
|
||||
--- error_log
|
||||
Buffer size not specified, bailing
|
||||
|
||||
|
||||
=== TEST 3: HTTP 1.0 body reader with no max size returns the right content length.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b",
|
||||
version = 1.0,
|
||||
}
|
||||
|
||||
local chunks = {}
|
||||
repeat
|
||||
local chunk = res.body_reader()
|
||||
if chunk then
|
||||
table.insert(chunks, chunk)
|
||||
end
|
||||
until not chunk
|
||||
|
||||
local body = table.concat(chunks)
|
||||
ngx.say(#body)
|
||||
ngx.say(res.headers["Transfer-Encoding"])
|
||||
ngx.say(#chunks)
|
||||
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
chunked_transfer_encoding off;
|
||||
content_by_lua '
|
||||
local len = 32768
|
||||
local t = {}
|
||||
for i=1,len do
|
||||
t[i] = 0
|
||||
end
|
||||
ngx.print(table.concat(t))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
32768
|
||||
nil
|
||||
1
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 4: HTTP 1.0 body reader with max chunk size returns the right content length.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b",
|
||||
version = 1.0,
|
||||
}
|
||||
|
||||
local chunks = {}
|
||||
local size = 8192
|
||||
repeat
|
||||
local chunk = res.body_reader(size)
|
||||
if chunk then
|
||||
table.insert(chunks, chunk)
|
||||
end
|
||||
size = size + size
|
||||
until not chunk
|
||||
|
||||
local body = table.concat(chunks)
|
||||
ngx.say(#body)
|
||||
ngx.say(res.headers["Transfer-Encoding"])
|
||||
ngx.say(#chunks)
|
||||
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
chunked_transfer_encoding off;
|
||||
content_by_lua '
|
||||
local len = 32769
|
||||
local t = {}
|
||||
for i=1,len do
|
||||
t[i] = 0
|
||||
end
|
||||
ngx.print(table.concat(t))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
32769
|
||||
nil
|
||||
3
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 4b: HTTP 1.0 body reader with no content length, stream works as expected.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b",
|
||||
version = 1.0,
|
||||
}
|
||||
|
||||
local chunks = {}
|
||||
local size = 8192
|
||||
repeat
|
||||
local chunk = res.body_reader(size)
|
||||
if chunk then
|
||||
table.insert(chunks, chunk)
|
||||
end
|
||||
size = size + size
|
||||
until not chunk
|
||||
|
||||
local body = table.concat(chunks)
|
||||
ngx.say(#body)
|
||||
ngx.say(#chunks)
|
||||
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.req.read_body()
|
||||
local sock, err = ngx.req.socket(true)
|
||||
if not sock then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
local res = {}
|
||||
table.insert(res, "HTTP/1.0 200 OK")
|
||||
table.insert(res, "Date: " .. ngx.http_time(ngx.time()))
|
||||
table.insert(res, "")
|
||||
|
||||
local len = 32769
|
||||
local t = {}
|
||||
for i=1,len do
|
||||
t[i] = 0
|
||||
end
|
||||
table.insert(res, table.concat(t))
|
||||
sock:send(table.concat(res, "\\r\\n"))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
32769
|
||||
3
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 5: Chunked streaming body reader with max chunk size returns the right content length.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b",
|
||||
}
|
||||
|
||||
local chunks = {}
|
||||
local size = 8192
|
||||
repeat
|
||||
local chunk = res.body_reader(size)
|
||||
if chunk then
|
||||
table.insert(chunks, chunk)
|
||||
end
|
||||
size = size + size
|
||||
until not chunk
|
||||
|
||||
local body = table.concat(chunks)
|
||||
ngx.say(#body)
|
||||
ngx.say(res.headers["Transfer-Encoding"])
|
||||
ngx.say(#chunks)
|
||||
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
local len = 32768
|
||||
local t = {}
|
||||
for i=1,len do
|
||||
t[i] = 0
|
||||
end
|
||||
ngx.print(table.concat(t))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
32768
|
||||
chunked
|
||||
3
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 6: Request reader correctly reads body
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
lua_need_request_body off;
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
|
||||
local reader, err = httpc:get_client_body_reader(8192)
|
||||
|
||||
repeat
|
||||
local chunk, err = reader()
|
||||
if chunk then
|
||||
ngx.print(chunk)
|
||||
end
|
||||
until chunk == nil
|
||||
|
||||
';
|
||||
}
|
||||
|
||||
--- request
|
||||
POST /a
|
||||
foobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbaz
|
||||
--- response_body: foobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbaz
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
=== TEST 7: Request reader correctly reads body in chunks
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
lua_need_request_body off;
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
|
||||
local reader, err = httpc:get_client_body_reader(64)
|
||||
|
||||
local chunks = 0
|
||||
repeat
|
||||
chunks = chunks +1
|
||||
local chunk, err = reader()
|
||||
if chunk then
|
||||
ngx.print(chunk)
|
||||
end
|
||||
until chunk == nil
|
||||
ngx.say("\\n"..chunks)
|
||||
';
|
||||
}
|
||||
|
||||
--- request
|
||||
POST /a
|
||||
foobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbaz
|
||||
--- response_body
|
||||
foobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbaz
|
||||
3
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 8: Request reader passes into client
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
lua_need_request_body off;
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local reader, err = httpc:get_client_body_reader(64)
|
||||
|
||||
local res, err = httpc:request{
|
||||
method = POST,
|
||||
path = "/b",
|
||||
body = reader,
|
||||
headers = ngx.req.get_headers(100, true),
|
||||
}
|
||||
|
||||
local body = res:read_body()
|
||||
ngx.say(body)
|
||||
httpc:close()
|
||||
|
||||
';
|
||||
}
|
||||
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.req.read_body()
|
||||
local body, err = ngx.req.get_body_data()
|
||||
ngx.print(body)
|
||||
';
|
||||
}
|
||||
|
||||
--- request
|
||||
POST /a
|
||||
foobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbaz
|
||||
--- response_body
|
||||
foobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbaz
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 9: Body reader is a function returning nil when no body is present.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b",
|
||||
method = "HEAD",
|
||||
}
|
||||
|
||||
repeat
|
||||
local chunk = res.body_reader()
|
||||
until not chunk
|
||||
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.exit(200)
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 10: Issue a notice (but do not error) if trying to read the request body in a subrequest
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
echo_location /b;
|
||||
}
|
||||
location = /b {
|
||||
lua_need_request_body off;
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
|
||||
local reader, err = httpc:get_client_body_reader(8192)
|
||||
if not reader then
|
||||
ngx.log(ngx.NOTICE, err)
|
||||
return
|
||||
end
|
||||
|
||||
repeat
|
||||
local chunk, err = reader()
|
||||
if chunk then
|
||||
ngx.print(chunk)
|
||||
end
|
||||
until chunk == nil
|
||||
';
|
||||
}
|
||||
|
||||
--- request
|
||||
POST /a
|
||||
foobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbazfoobarbaz
|
||||
--- response_body:
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
--- error_log
|
||||
attempt to read the request body in a subrequest
|
||||
338
src/deps/src/lua-resty-http/t/06-simpleinterface.t
vendored
338
src/deps/src/lua-resty-http/t/06-simpleinterface.t
vendored
|
|
@ -1,338 +0,0 @@
|
|||
use Test::Nginx::Socket 'no_plan';
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
}
|
||||
};
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
=== TEST 1: Simple URI interface
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
local res, err = httpc:request_uri("http://127.0.0.1:"..ngx.var.server_port.."/b?a=1&b=2")
|
||||
|
||||
if not res then
|
||||
ngx.log(ngx.ERR, err)
|
||||
end
|
||||
ngx.status = res.status
|
||||
|
||||
ngx.header["X-Header-A"] = res.headers["X-Header-A"]
|
||||
ngx.header["X-Header-B"] = res.headers["X-Header-B"]
|
||||
|
||||
ngx.print(res.body)
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
for k,v in pairs(ngx.req.get_uri_args()) do
|
||||
ngx.header["X-Header-" .. string.upper(k)] = v
|
||||
end
|
||||
ngx.say("OK")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_headers
|
||||
X-Header-A: 1
|
||||
X-Header-B: 2
|
||||
--- response_body
|
||||
OK
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 2: Simple URI interface HTTP 1.0
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
local res, err = httpc:request_uri(
|
||||
"http://127.0.0.1:"..ngx.var.server_port.."/b?a=1&b=2", {
|
||||
}
|
||||
)
|
||||
|
||||
ngx.status = res.status
|
||||
|
||||
ngx.header["X-Header-A"] = res.headers["X-Header-A"]
|
||||
ngx.header["X-Header-B"] = res.headers["X-Header-B"]
|
||||
|
||||
ngx.print(res.body)
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
for k,v in pairs(ngx.req.get_uri_args()) do
|
||||
ngx.header["X-Header-" .. string.upper(k)] = v
|
||||
end
|
||||
ngx.say("OK")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_headers
|
||||
X-Header-A: 1
|
||||
X-Header-B: 2
|
||||
--- response_body
|
||||
OK
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 3 Simple URI interface, params override
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
local res, err = httpc:request_uri(
|
||||
"http://127.0.0.1:"..ngx.var.server_port.."/b?a=1&b=2", {
|
||||
path = "/c",
|
||||
query = {
|
||||
a = 2,
|
||||
b = 3,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
ngx.status = res.status
|
||||
|
||||
ngx.header["X-Header-A"] = res.headers["X-Header-A"]
|
||||
ngx.header["X-Header-B"] = res.headers["X-Header-B"]
|
||||
|
||||
ngx.print(res.body)
|
||||
';
|
||||
}
|
||||
location = /c {
|
||||
content_by_lua '
|
||||
for k,v in pairs(ngx.req.get_uri_args()) do
|
||||
ngx.header["X-Header-" .. string.upper(k)] = v
|
||||
end
|
||||
ngx.say("OK")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_headers
|
||||
X-Header-A: 2
|
||||
X-Header-B: 3
|
||||
--- response_body
|
||||
OK
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 4 Simple URI interface, params override, query as string
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
local res, err = httpc:request_uri(
|
||||
"http://127.0.0.1:"..ngx.var.server_port.."/b?a=1&b=2", {
|
||||
path = "/c",
|
||||
query = "a=2&b=3",
|
||||
}
|
||||
)
|
||||
|
||||
ngx.status = res.status
|
||||
|
||||
ngx.header["X-Header-A"] = res.headers["X-Header-A"]
|
||||
ngx.header["X-Header-B"] = res.headers["X-Header-B"]
|
||||
|
||||
ngx.print(res.body)
|
||||
';
|
||||
}
|
||||
location = /c {
|
||||
content_by_lua '
|
||||
for k,v in pairs(ngx.req.get_uri_args()) do
|
||||
ngx.header["X-Header-" .. string.upper(k)] = v
|
||||
end
|
||||
ngx.say("OK")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_headers
|
||||
X-Header-A: 2
|
||||
X-Header-B: 3
|
||||
--- response_body
|
||||
OK
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 5 Simple URI interface, params override, query as string, as leading ?
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
local res, err = httpc:request_uri(
|
||||
"http://127.0.0.1:"..ngx.var.server_port.."/b?a=1&b=2", {
|
||||
query = "?a=2&b=3",
|
||||
}
|
||||
)
|
||||
|
||||
ngx.status = res.status
|
||||
|
||||
ngx.header["X-Header-A"] = res.headers["X-Header-A"]
|
||||
ngx.header["X-Header-B"] = res.headers["X-Header-B"]
|
||||
|
||||
ngx.print(res.body)
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
for k,v in pairs(ngx.req.get_uri_args()) do
|
||||
ngx.header["X-Header-" .. string.upper(k)] = v
|
||||
end
|
||||
ngx.say("OK")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_headers
|
||||
X-Header-A: 2
|
||||
X-Header-B: 3
|
||||
--- response_body
|
||||
OK
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
=== TEST 6: Connection is closed on error
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
lua_socket_read_timeout 100ms;
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
local res, err = httpc:request_uri("http://127.0.0.1:"..ngx.var.server_port.."/b?a=1&b=2")
|
||||
|
||||
if not res then
|
||||
ngx.log(ngx.ERR, err)
|
||||
else
|
||||
return ngx.say("BAD")
|
||||
end
|
||||
|
||||
local ok, err = httpc.sock:close()
|
||||
ngx.say(ok, " ", err)
|
||||
|
||||
}
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua_block {
|
||||
ngx.say("1")
|
||||
ngx.flush(true)
|
||||
ngx.sleep(0.5)
|
||||
ngx.say("2")
|
||||
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
nil closed
|
||||
--- error_log
|
||||
lua tcp socket read timed out
|
||||
|
||||
|
||||
=== TEST 7: Content-Length is set on POST/PUT/PATCH requests when body is absent
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
for i, method in ipairs({ "POST", "PUT", "PATCH" }) do
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
local res, err = httpc:request_uri("http://127.0.0.1:"..ngx.var.server_port.."/b", { method = method })
|
||||
|
||||
if not res then
|
||||
ngx.log(ngx.ERR, err)
|
||||
end
|
||||
|
||||
if i == 1 then
|
||||
ngx.status = res.status
|
||||
end
|
||||
|
||||
ngx.print(res.body)
|
||||
end
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.say(ngx.req.get_method(), " Content-Length: ", ngx.req.get_headers()["Content-Length"])
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
POST Content-Length: 0
|
||||
PUT Content-Length: 0
|
||||
PATCH Content-Length: 0
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 8: Content-Length is not set on GET requests when body is absent
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
local res, err = httpc:request_uri("http://127.0.0.1:"..ngx.var.server_port.."/b")
|
||||
|
||||
if not res then
|
||||
ngx.log(ngx.ERR, err)
|
||||
end
|
||||
ngx.status = res.status
|
||||
ngx.print(res.body)
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.say("Content-Length: ", type(ngx.req.get_headers()["Content-Length"]))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
Content-Length: nil
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
434
src/deps/src/lua-resty-http/t/07-keepalive.t
vendored
434
src/deps/src/lua-resty-http/t/07-keepalive.t
vendored
|
|
@ -1,434 +0,0 @@
|
|||
use Test::Nginx::Socket 'no_plan';
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
}
|
||||
};
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
=== TEST 1 Simple interface, Connection: Keep-alive. Test the connection is reused.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
local res, err = httpc:request_uri(
|
||||
"http://127.0.0.1:" .. ngx.var.server_port.."/b", {}
|
||||
)
|
||||
ngx.say(res.headers["Connection"])
|
||||
|
||||
httpc:connect {
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
}
|
||||
ngx.say(httpc:get_reused_times())
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.say("OK")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
keep-alive
|
||||
1
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 2 Simple interface, Connection: close, test we don't try to keepalive, but also that subsequent connections can keepalive.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
local res, err = httpc:request_uri(
|
||||
"http://127.0.0.1:"..ngx.var.server_port.."/b", {
|
||||
version = 1.0,
|
||||
headers = {
|
||||
["Connection"] = "close",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
ngx.say(httpc:get_reused_times())
|
||||
|
||||
httpc:set_keepalive()
|
||||
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
ngx.say(httpc:get_reused_times())
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.say("OK")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
0
|
||||
1
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 3 Generic interface, Connection: Keep-alive. Test the connection is reused.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b"
|
||||
}
|
||||
|
||||
local body = res:read_body()
|
||||
|
||||
ngx.say(res.headers["Connection"])
|
||||
ngx.say(httpc:set_keepalive())
|
||||
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
ngx.say(httpc:get_reused_times())
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.say("OK")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
keep-alive
|
||||
1
|
||||
1
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 4 Generic interface, Connection: Close. Test we don't try to keepalive, but also that subsequent connections can keepalive.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
version = 1.0,
|
||||
headers = {
|
||||
["Connection"] = "Close",
|
||||
},
|
||||
path = "/b"
|
||||
}
|
||||
|
||||
local body = res:read_body()
|
||||
|
||||
ngx.say(res.headers["Connection"])
|
||||
local r, e = httpc:set_keepalive()
|
||||
ngx.say(r)
|
||||
ngx.say(e)
|
||||
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
ngx.say(httpc:get_reused_times())
|
||||
|
||||
httpc:set_keepalive()
|
||||
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
ngx.say(httpc:get_reused_times())
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.say("OK")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
close
|
||||
2
|
||||
connection must be closed
|
||||
0
|
||||
1
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 5: Generic interface, HTTP 1.0, no connection header. Test we don't try to keepalive, but also that subsequent connections can keepalive.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = 12345,
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
version = 1.0,
|
||||
path = "/b"
|
||||
}
|
||||
|
||||
local body = res:read_body()
|
||||
ngx.print(body)
|
||||
|
||||
ngx.say(res.headers["Connection"])
|
||||
|
||||
local r, e = httpc:set_keepalive()
|
||||
ngx.say(r)
|
||||
ngx.say(e)
|
||||
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
ngx.say(httpc:get_reused_times())
|
||||
|
||||
httpc:set_keepalive()
|
||||
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
ngx.say(httpc:get_reused_times())
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.say("OK")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- tcp_listen: 12345
|
||||
--- tcp_reply
|
||||
HTTP/1.0 200 OK
|
||||
Date: Fri, 08 Aug 2016 08:12:31 GMT
|
||||
Server: OpenResty
|
||||
|
||||
OK
|
||||
--- response_body
|
||||
OK
|
||||
nil
|
||||
2
|
||||
connection must be closed
|
||||
0
|
||||
1
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
=== TEST 6: Simple interface, override settings
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
local res, err = httpc:request_uri(
|
||||
"http://127.0.0.1:"..ngx.var.server_port.."/b",
|
||||
{
|
||||
keepalive = false
|
||||
}
|
||||
)
|
||||
|
||||
ngx.say(res.headers["Connection"])
|
||||
|
||||
httpc:connect {
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
}
|
||||
ngx.say(httpc:get_reused_times())
|
||||
httpc:close()
|
||||
|
||||
local res, err = httpc:request_uri(
|
||||
"http://127.0.0.1:"..ngx.var.server_port.."/b",
|
||||
{
|
||||
keepalive_timeout = 10
|
||||
}
|
||||
)
|
||||
|
||||
ngx.say(res.headers["Connection"])
|
||||
|
||||
httpc:connect {
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
}
|
||||
ngx.say(httpc:get_reused_times())
|
||||
httpc:close()
|
||||
|
||||
local res, err = httpc:request_uri(
|
||||
"http://127.0.0.1:"..ngx.var.server_port.."/b",
|
||||
{
|
||||
keepalive_timeout = 1
|
||||
}
|
||||
)
|
||||
|
||||
ngx.say(res.headers["Connection"])
|
||||
|
||||
ngx.sleep(1.1)
|
||||
|
||||
httpc:connect {
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
}
|
||||
ngx.say(httpc:get_reused_times())
|
||||
httpc:close()
|
||||
}
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua_block {
|
||||
ngx.say("OK")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
keep-alive
|
||||
0
|
||||
keep-alive
|
||||
1
|
||||
keep-alive
|
||||
0
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
=== TEST 7: Generic interface, HTTP 1.1, Connection: Upgrade, close. Test we don't try to keepalive, but also that subsequent connections can keepalive.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
|
||||
-- Create a TCP connection and return an raw HTTP-response because
|
||||
-- there is no way to set an "Connection: Upgrade, close" header in nginx.
|
||||
assert(httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = 12345,
|
||||
}), "connect should return positively")
|
||||
|
||||
local res = httpc:request({
|
||||
version = 1.1,
|
||||
path = "/b",
|
||||
})
|
||||
|
||||
local body = res:read_body()
|
||||
ngx.print(body)
|
||||
|
||||
ngx.say(res.headers["Connection"])
|
||||
|
||||
local r, e = httpc:set_keepalive()
|
||||
ngx.say(r)
|
||||
ngx.say(e)
|
||||
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
ngx.say(httpc:get_reused_times())
|
||||
|
||||
httpc:set_keepalive()
|
||||
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
ngx.say(httpc:get_reused_times())
|
||||
}
|
||||
}
|
||||
--- tcp_listen: 12345
|
||||
--- tcp_reply
|
||||
HTTP/1.1 200 OK
|
||||
Date: Wed, 08 Aug 2018 17:00:00 GMT
|
||||
Server: Apache/2
|
||||
Upgrade: h2,h2c
|
||||
Connection: Upgrade, close
|
||||
|
||||
OK
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
OK
|
||||
Upgrade, close
|
||||
2
|
||||
connection must be closed
|
||||
0
|
||||
1
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
155
src/deps/src/lua-resty-http/t/08-pipeline.t
vendored
155
src/deps/src/lua-resty-http/t/08-pipeline.t
vendored
|
|
@ -1,155 +0,0 @@
|
|||
use Test::Nginx::Socket 'no_plan';
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
}
|
||||
};
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
=== TEST 1 Test that pipelined requests can be read correctly.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
|
||||
local responses = httpc:request_pipeline{
|
||||
{
|
||||
path = "/b",
|
||||
},
|
||||
{
|
||||
path = "/c",
|
||||
},
|
||||
{
|
||||
path = "/d",
|
||||
}
|
||||
}
|
||||
|
||||
for i,r in ipairs(responses) do
|
||||
if r.status then
|
||||
ngx.say(r.status)
|
||||
ngx.say(r.headers["X-Res"])
|
||||
ngx.say(r:read_body())
|
||||
end
|
||||
end
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.status = 200
|
||||
ngx.header["X-Res"] = "B"
|
||||
ngx.print("B")
|
||||
';
|
||||
}
|
||||
location = /c {
|
||||
content_by_lua '
|
||||
ngx.status = 404
|
||||
ngx.header["X-Res"] = "C"
|
||||
ngx.print("C")
|
||||
';
|
||||
}
|
||||
location = /d {
|
||||
content_by_lua '
|
||||
ngx.status = 200
|
||||
ngx.header["X-Res"] = "D"
|
||||
ngx.print("D")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
200
|
||||
B
|
||||
B
|
||||
404
|
||||
C
|
||||
C
|
||||
200
|
||||
D
|
||||
D
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 2: Test we can handle timeouts on reading the pipelined requests.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port
|
||||
})
|
||||
httpc:set_timeout(1)
|
||||
|
||||
local responses = httpc:request_pipeline{
|
||||
{
|
||||
path = "/b",
|
||||
},
|
||||
{
|
||||
path = "/c",
|
||||
},
|
||||
}
|
||||
|
||||
for i,r in ipairs(responses) do
|
||||
if r.status then
|
||||
ngx.say(r.status)
|
||||
ngx.say(r.headers["X-Res"])
|
||||
ngx.say(r:read_body())
|
||||
end
|
||||
end
|
||||
';
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
ngx.status = 200
|
||||
ngx.header["X-Res"] = "B"
|
||||
ngx.print("B")
|
||||
';
|
||||
}
|
||||
location = /c {
|
||||
content_by_lua '
|
||||
ngx.status = 404
|
||||
ngx.header["X-Res"] = "C"
|
||||
ngx.sleep(1)
|
||||
ngx.print("C")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
200
|
||||
B
|
||||
B
|
||||
--- no_error_log
|
||||
[warn]
|
||||
--- error_log eval
|
||||
[qr/timeout/]
|
||||
64
src/deps/src/lua-resty-http/t/09-ssl.t
vendored
64
src/deps/src/lua-resty-http/t/09-ssl.t
vendored
|
|
@ -1,64 +0,0 @@
|
|||
use Test::Nginx::Socket 'no_plan';
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
}
|
||||
};
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
=== TEST 1: parse_uri returns port 443 for https URIs
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
local parsed = httpc:parse_uri("https://www.google.com/foobar")
|
||||
ngx.say(parsed[3])
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
443
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 2: parse_uri returns port 80 for http URIs
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
local parsed = httpc:parse_uri("http://www.google.com/foobar")
|
||||
ngx.say(parsed[3])
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
80
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
122
src/deps/src/lua-resty-http/t/10-clientbodyreader.t
vendored
122
src/deps/src/lua-resty-http/t/10-clientbodyreader.t
vendored
|
|
@ -1,122 +0,0 @@
|
|||
use Test::Nginx::Socket 'no_plan';
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
}
|
||||
};
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
=== TEST 1: Issue a notice (but do not error) if trying to read the request body in a subrequest
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
echo_location /b;
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port,
|
||||
})
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/c",
|
||||
headers = {
|
||||
["Content-Type"] = "application/x-www-form-urlencoded",
|
||||
}
|
||||
}
|
||||
if not res then
|
||||
ngx.say(err)
|
||||
end
|
||||
ngx.print(res:read_body())
|
||||
httpc:close()
|
||||
';
|
||||
}
|
||||
location /c {
|
||||
echo "OK";
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
OK
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 2: Read request body
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local httpc = require("resty.http").new()
|
||||
|
||||
local reader, err = assert(httpc:get_client_body_reader())
|
||||
|
||||
repeat
|
||||
local buffer, err = reader()
|
||||
if err then
|
||||
ngx.log(ngx.ERR, err)
|
||||
end
|
||||
|
||||
if buffer then
|
||||
ngx.print(buffer)
|
||||
end
|
||||
until not buffer
|
||||
}
|
||||
}
|
||||
--- request
|
||||
POST /a
|
||||
foobar
|
||||
--- response_body: foobar
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 2: Read chunked request body, errors as not yet supported
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local httpc = require("resty.http").new()
|
||||
local _, err = httpc:get_client_body_reader()
|
||||
ngx.log(ngx.ERR, err)
|
||||
}
|
||||
}
|
||||
--- more_headers
|
||||
Transfer-Encoding: chunked
|
||||
--- request eval
|
||||
"POST /a
|
||||
3\r
|
||||
foo\r
|
||||
3\r
|
||||
bar\r
|
||||
0\r
|
||||
\r
|
||||
"
|
||||
--- error_log
|
||||
chunked request bodies not supported yet
|
||||
--- no_error_log
|
||||
[warn]
|
||||
182
src/deps/src/lua-resty-http/t/11-proxy.t
vendored
182
src/deps/src/lua-resty-http/t/11-proxy.t
vendored
|
|
@ -1,182 +0,0 @@
|
|||
use Test::Nginx::Socket 'no_plan';
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
=== TEST 1: Proxy GET request and response
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a_prx {
|
||||
rewrite ^(.*)_prx$ $1 break;
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port,
|
||||
})
|
||||
httpc:proxy_response(httpc:proxy_request())
|
||||
httpc:set_keepalive()
|
||||
';
|
||||
}
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
ngx.status = 200
|
||||
ngx.header["X-Test"] = "foo"
|
||||
ngx.say("OK")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a_prx
|
||||
--- response_body
|
||||
OK
|
||||
--- response_headers
|
||||
X-Test: foo
|
||||
--- error_code: 200
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
--- error_log
|
||||
[debug]
|
||||
|
||||
|
||||
=== TEST 2: Proxy POST request and response
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a_prx {
|
||||
rewrite ^(.*)_prx$ $1 break;
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port,
|
||||
})
|
||||
httpc:proxy_response(httpc:proxy_request())
|
||||
httpc:set_keepalive()
|
||||
';
|
||||
}
|
||||
location = /a {
|
||||
lua_need_request_body on;
|
||||
content_by_lua '
|
||||
ngx.status = 404
|
||||
ngx.header["X-Test"] = "foo"
|
||||
local args, err = ngx.req.get_post_args()
|
||||
ngx.say(args["foo"])
|
||||
ngx.say(args["hello"])
|
||||
';
|
||||
}
|
||||
--- request
|
||||
POST /a_prx
|
||||
foo=bar&hello=world
|
||||
--- response_body
|
||||
bar
|
||||
world
|
||||
--- response_headers
|
||||
X-Test: foo
|
||||
--- error_code: 404
|
||||
--- no_error_log
|
||||
[error]
|
||||
--- error_log
|
||||
[warn]
|
||||
--- error_log
|
||||
[debug]
|
||||
|
||||
|
||||
=== TEST 3: Proxy multiple headers
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a_prx {
|
||||
rewrite ^(.*)_prx$ $1 break;
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port,
|
||||
})
|
||||
httpc:proxy_response(httpc:proxy_request())
|
||||
httpc:set_keepalive()
|
||||
';
|
||||
}
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
ngx.status = 200
|
||||
ngx.header["Set-Cookie"] = { "cookie1", "cookie2" }
|
||||
ngx.say("OK")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a_prx
|
||||
--- response_body
|
||||
OK
|
||||
--- raw_response_headers_like: .*Set-Cookie: cookie1\r\nSet-Cookie: cookie2\r\n
|
||||
--- error_code: 200
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
--- error_log
|
||||
[debug]
|
||||
|
||||
|
||||
=== TEST 4: Proxy still works with spaces in URI
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = "/a_ b_prx" {
|
||||
rewrite ^(.*)_prx$ $1 break;
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:connect({
|
||||
scheme = "http",
|
||||
host = "127.0.0.1",
|
||||
port = ngx.var.server_port,
|
||||
})
|
||||
httpc:proxy_response(httpc:proxy_request())
|
||||
httpc:set_keepalive()
|
||||
';
|
||||
}
|
||||
location = "/a_ b" {
|
||||
content_by_lua '
|
||||
ngx.status = 200
|
||||
ngx.header["X-Test"] = "foo"
|
||||
ngx.say("OK")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a_%20b_prx
|
||||
--- response_body
|
||||
OK
|
||||
--- response_headers
|
||||
X-Test: foo
|
||||
--- error_code: 200
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
--- error_log
|
||||
[debug]
|
||||
|
|
@ -1,182 +0,0 @@
|
|||
use Test::Nginx::Socket 'no_plan';
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;;";
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
}
|
||||
|
||||
underscores_in_headers On;
|
||||
};
|
||||
|
||||
no_long_string();
|
||||
no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
=== TEST 1: Unit test header normalisation
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local headers = require("resty.http_headers").new()
|
||||
|
||||
headers["content-length"] = "a"
|
||||
headers["TRANSFER-ENCODING"] = "b"
|
||||
headers["SSL_CLIENT_CERTIFICATE"] = "foo"
|
||||
|
||||
assert(headers["coNtENt-LENgth"] == headers["content-length"],
|
||||
"header values should match")
|
||||
|
||||
assert(headers["transfer-encoding"] == headers["TRANSFER-ENCODING"],
|
||||
"header values should match")
|
||||
|
||||
assert(headers["ssl_client_certificate"] == headers["SSL_CLIENT_CERTIFICATE"],
|
||||
"header values should match")
|
||||
|
||||
assert(headers["SSL-CLIENT-CERTIFICATE"] ~= headers["SSL_CLIENT_CERTIFICATE"],
|
||||
"underscores are separate to hyphens")
|
||||
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
=== TEST 2: Integration test headers normalisation
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local httpc = require("resty.http").new()
|
||||
assert(httpc:connect("127.0.0.1", ngx.var.server_port),
|
||||
"connect should return positively")
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b"
|
||||
}
|
||||
|
||||
ngx.status = res.status
|
||||
ngx.say(res.headers["X-Foo-Header"])
|
||||
ngx.say(res.headers["x-fOo-heaDeR"])
|
||||
|
||||
httpc:close()
|
||||
}
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua_block {
|
||||
ngx.header["X-Foo-Header"] = "bar"
|
||||
ngx.say("OK")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
bar
|
||||
bar
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
=== TEST 3: Integration test request headers normalisation
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local httpc = require("resty.http").new()
|
||||
assert(httpc:connect("127.0.0.1", ngx.var.server_port),
|
||||
"connect should return positively")
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b",
|
||||
headers = {
|
||||
["uSeR-AgENT"] = "test_user_agent",
|
||||
["X_Foo"] = "bar",
|
||||
},
|
||||
}
|
||||
|
||||
ngx.status = res.status
|
||||
ngx.print(res:read_body())
|
||||
|
||||
httpc:close()
|
||||
}
|
||||
}
|
||||
location = /b {
|
||||
content_by_lua_block {
|
||||
ngx.say(ngx.req.get_headers()["User-Agent"])
|
||||
ngx.say(ngx.req.get_headers(nil, true)["X_Foo"])
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
test_user_agent
|
||||
bar
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
=== TEST 4: Test that headers remain unique
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local headers = require("resty.http_headers").new()
|
||||
|
||||
headers["x-a-header"] = "a"
|
||||
headers["X-A-HEAder"] = "b"
|
||||
|
||||
for k,v in pairs(headers) do
|
||||
ngx.header[k] = v
|
||||
end
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_headers
|
||||
x-a-header: b
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
=== TEST 5: Prove header tables are always unique
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua_block {
|
||||
local headers = require("resty.http_headers").new()
|
||||
|
||||
headers["content-length"] = "a"
|
||||
headers["TRANSFER-ENCODING"] = "b"
|
||||
headers["SSL_CLIENT_CERTIFICATE"] = "foo"
|
||||
|
||||
local headers2 = require("resty.http_headers").new()
|
||||
|
||||
assert(headers2 ~= headers,
|
||||
"headers should be unique")
|
||||
|
||||
assert(not next(headers2),
|
||||
"headers2 should be empty")
|
||||
|
||||
assert(not next(getmetatable(headers2).normalised),
|
||||
"headers normalised data should be empty")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
--- no_error_log
|
||||
[error]
|
||||
55
src/deps/src/lua-resty-http/t/13-default-path.t
vendored
55
src/deps/src/lua-resty-http/t/13-default-path.t
vendored
|
|
@ -1,55 +0,0 @@
|
|||
use Test::Nginx::Socket 'no_plan';
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
}
|
||||
};
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
=== TEST 1: request_uri (check the default path)
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /lua {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
|
||||
local res, err = httpc:request_uri("http://127.0.0.1:"..ngx.var.server_port)
|
||||
|
||||
if res and 200 == res.status then
|
||||
ngx.say("OK")
|
||||
else
|
||||
ngx.say("FAIL")
|
||||
end
|
||||
';
|
||||
}
|
||||
|
||||
location =/ {
|
||||
content_by_lua '
|
||||
ngx.print("OK")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /lua
|
||||
--- response_body
|
||||
OK
|
||||
--- no_error_log
|
||||
[error]
|
||||
198
src/deps/src/lua-resty-http/t/14-host-header.t
vendored
198
src/deps/src/lua-resty-http/t/14-host-header.t
vendored
|
|
@ -1,198 +0,0 @@
|
|||
use Test::Nginx::Socket 'no_plan';
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
$ENV{TEST_NGINX_PWD} ||= $pwd;
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
resolver 8.8.8.8 ipv6=off;
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
|
||||
require("resty.http").debug(true)
|
||||
}
|
||||
};
|
||||
|
||||
sub read_file {
|
||||
my $infile = shift;
|
||||
open my $in, $infile
|
||||
or die "cannot open $infile for reading: $!";
|
||||
my $cert = do { local $/; <$in> };
|
||||
close $in;
|
||||
$cert;
|
||||
}
|
||||
|
||||
our $TestCertificate = read_file("t/cert/test.crt");
|
||||
our $TestCertificateKey = read_file("t/cert/test.key");
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
=== TEST 1: Default HTTP port is not added to Host header
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /lua {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
|
||||
local res, err = httpc:request_uri("http://www.google.com")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /lua
|
||||
--- no_error_log
|
||||
[error]
|
||||
--- error_log
|
||||
Host: www.google.com
|
||||
|
||||
|
||||
=== TEST 2: Default HTTPS port is not added to Host header
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /lua {
|
||||
content_by_lua '
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
|
||||
httpc:set_timeouts(300, 1000, 1000)
|
||||
local res, err = httpc:request_uri("https://www.google.com:443", { ssl_verify = false })
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /lua
|
||||
--- no_error_log
|
||||
[error]
|
||||
--- error_log
|
||||
Host: www.google.com
|
||||
|
||||
|
||||
=== TEST 3: Non-default HTTP port is added to Host header
|
||||
--- http_config
|
||||
lua_package_path "$TEST_NGINX_PWD/lib/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
resolver 8.8.8.8;
|
||||
server {
|
||||
listen *:8080;
|
||||
}
|
||||
--- config
|
||||
location /lua {
|
||||
content_by_lua '
|
||||
require("resty.http").debug(true)
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
|
||||
local res, err = httpc:request_uri("http://127.0.0.1:8080")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /lua
|
||||
--- no_error_log
|
||||
[error]
|
||||
--- error_log
|
||||
Host: 127.0.0.1:8080
|
||||
|
||||
|
||||
=== TEST 4: Non-default HTTPS port is added to Host header
|
||||
--- http_config
|
||||
lua_package_path "$TEST_NGINX_PWD/lib/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
resolver 8.8.8.8;
|
||||
server {
|
||||
listen *:8080;
|
||||
listen *:8081 ssl;
|
||||
ssl_certificate ../html/test.crt;
|
||||
ssl_certificate_key ../html/test.key;
|
||||
}
|
||||
--- config
|
||||
location /lua {
|
||||
content_by_lua '
|
||||
require("resty.http").debug(true)
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
|
||||
local res, err = httpc:request_uri("https://127.0.0.1:8081", { ssl_verify = false })
|
||||
';
|
||||
}
|
||||
--- user_files eval
|
||||
">>> test.key
|
||||
$::TestCertificateKey
|
||||
>>> test.crt
|
||||
$::TestCertificate"
|
||||
--- request
|
||||
GET /lua
|
||||
--- no_error_log
|
||||
[error]
|
||||
--- error_log
|
||||
Host: 127.0.0.1:8081
|
||||
|
||||
|
||||
=== TEST 5: No host header on a unix domain socket returns a useful error.
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /a {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
|
||||
local res, err = httpc:connect("unix:.test.sock")
|
||||
if not res then
|
||||
ngx.log(ngx.ERR, err)
|
||||
end
|
||||
|
||||
local res, err = httpc:request({ path = "/" })
|
||||
if not res then
|
||||
ngx.say(err)
|
||||
else
|
||||
ngx.say(res:read_body())
|
||||
end
|
||||
}
|
||||
}
|
||||
--- tcp_listen: .test.sock
|
||||
--- tcp_reply: OK
|
||||
--- request
|
||||
GET /a
|
||||
--- no_error_log
|
||||
[error]
|
||||
--- response_body
|
||||
Unable to generate a useful Host header for a unix domain socket. Please provide one.
|
||||
|
||||
=== TEST 6: Host header is correct when http_proxy is used
|
||||
--- http_config
|
||||
lua_package_path "$TEST_NGINX_PWD/lib/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
resolver 8.8.8.8;
|
||||
server {
|
||||
listen *:8080;
|
||||
}
|
||||
|
||||
--- config
|
||||
location /lua {
|
||||
content_by_lua '
|
||||
require("resty.http").debug(true)
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:set_proxy_options({
|
||||
http_proxy = "http://127.0.0.1:8080"
|
||||
})
|
||||
local res, err = httpc:request_uri("http://127.0.0.1:8081")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /lua
|
||||
--- no_error_log
|
||||
[error]
|
||||
--- error_log
|
||||
Host: 127.0.0.1:8081
|
||||
138
src/deps/src/lua-resty-http/t/15-instance-reuse.t
vendored
138
src/deps/src/lua-resty-http/t/15-instance-reuse.t
vendored
|
|
@ -1,138 +0,0 @@
|
|||
use Test::Nginx::Socket 'no_plan';
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
$ENV{TEST_NGINX_PWD} ||= $pwd;
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;;";
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
}
|
||||
};
|
||||
|
||||
no_long_string();
|
||||
no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
|
||||
__DATA__
|
||||
=== TEST 1: Reuse an instance connecting on different ports / paths
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /a {
|
||||
content_by_lua_block {
|
||||
local httpc = require("resty.http").new()
|
||||
|
||||
assert(httpc:connect("127.0.0.1", ngx.var.server_port),
|
||||
"connect should return positively")
|
||||
|
||||
local res1 = httpc:request({ path = "/b" })
|
||||
ngx.print(res1:read_body())
|
||||
|
||||
local res2 = httpc:request({ path = "/c" })
|
||||
ngx.print(res2:read_body())
|
||||
|
||||
assert(res1 ~= res2, "responses should be unique tables")
|
||||
assert(res1.headers ~= res2.headers, "headers should be unique tables")
|
||||
|
||||
assert(httpc:connect("127.0.0.1", 12345),
|
||||
"connect should return positively")
|
||||
|
||||
local res3 = httpc:request({ path = "/b" })
|
||||
ngx.print(res3:read_body())
|
||||
|
||||
assert(res3 ~= res2, "responses should be unique tables")
|
||||
assert(res3.headers ~= res2.headers, "headers should be unique tables")
|
||||
|
||||
assert(httpc.keepalive == false, "keepalive flag should be false")
|
||||
|
||||
assert(httpc:connect("127.0.0.1", ngx.var.server_port),
|
||||
"connect should return positively")
|
||||
|
||||
assert(httpc.keepalive == true, "keepalive flag should be true")
|
||||
|
||||
}
|
||||
}
|
||||
location /b {
|
||||
echo "b";
|
||||
}
|
||||
location /c {
|
||||
echo "c";
|
||||
}
|
||||
--- tcp_listen: 12345
|
||||
--- tcp_reply
|
||||
HTTP/1.0 200 OK
|
||||
Date: Fri, 08 Aug 2016 08:12:31 GMT
|
||||
Server: OpenResty
|
||||
|
||||
d
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
b
|
||||
c
|
||||
d
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
=== TEST 2: Reuse input params table
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /a {
|
||||
content_by_lua_block {
|
||||
local httpc = require("resty.http").new()
|
||||
|
||||
assert(httpc:connect("127.0.0.1", ngx.var.server_port),
|
||||
"connect should return positively")
|
||||
|
||||
local params = {
|
||||
path = "/b",
|
||||
method = "HEAD",
|
||||
}
|
||||
|
||||
local res, err = httpc:request(params)
|
||||
assert(res, "request should return positvely")
|
||||
|
||||
assert(not params.headers, "params table should not be modified")
|
||||
|
||||
local res, err =
|
||||
httpc:request_uri("http://127.0.0.1:"..ngx.var.server_port, params)
|
||||
assert(res, "request_uri should return positvely")
|
||||
|
||||
assert(not params.headers, "params table should not be modified")
|
||||
|
||||
|
||||
assert(httpc:connect("127.0.0.1", ngx.var.server_port),
|
||||
"connect should return positively")
|
||||
|
||||
local pipeline_params = {
|
||||
{ path = "/b", method = "POST" },
|
||||
{ path = "/b", method = "HEAD" },
|
||||
}
|
||||
|
||||
local res, err = httpc:request_pipeline(pipeline_params)
|
||||
assert(res, "request_pipeline should return positively")
|
||||
|
||||
assert(not pipeline_params[1].headers and not pipeline_params[2].headers,
|
||||
"params tables should not be modified")
|
||||
|
||||
}
|
||||
}
|
||||
location /b {
|
||||
echo "b";
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
--- no_error_log
|
||||
[error]
|
||||
520
src/deps/src/lua-resty-http/t/16-http-proxy.t
vendored
520
src/deps/src/lua-resty-http/t/16-http-proxy.t
vendored
|
|
@ -1,520 +0,0 @@
|
|||
use Test::Nginx::Socket 'no_plan';
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
$ENV{TEST_NGINX_PWD} ||= $pwd;
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
resolver 8.8.8.8;
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
}
|
||||
};
|
||||
|
||||
no_long_string();
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: get_proxy_uri returns nil if proxy is not configured
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /lua {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
ngx.say(httpc:get_proxy_uri("http", "example.com"))
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /lua
|
||||
--- response_body
|
||||
nil
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
|
||||
=== TEST 2: get_proxy_uri matches no_proxy hosts correctly
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /lua {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
|
||||
-- helper that verifies get_proxy_uri works correctly with the given
|
||||
-- scheme, host and no_proxy list
|
||||
local function test_no_proxy(scheme, host, no_proxy)
|
||||
httpc:set_proxy_options({
|
||||
http_proxy = "http://http_proxy.example.com",
|
||||
https_proxy = "http://https_proxy.example.com",
|
||||
no_proxy = no_proxy
|
||||
})
|
||||
|
||||
local proxy_uri = httpc:get_proxy_uri(scheme, host)
|
||||
ngx.say("scheme: ", scheme, ", host: ", host, ", no_proxy: ", no_proxy, ", proxy_uri: ", proxy_uri)
|
||||
end
|
||||
|
||||
-- All these match the no_proxy list
|
||||
test_no_proxy("http", "example.com", nil)
|
||||
test_no_proxy("http", "example.com", "*")
|
||||
test_no_proxy("http", "example.com", "example.com")
|
||||
test_no_proxy("http", "sub.example.com", "example.com")
|
||||
test_no_proxy("http", "example.com", "example.com,example.org")
|
||||
test_no_proxy("http", "example.com", "example.org,example.com")
|
||||
|
||||
-- Same for https for good measure
|
||||
test_no_proxy("https", "example.com", nil)
|
||||
test_no_proxy("https", "example.com", "*")
|
||||
test_no_proxy("https", "example.com", "example.com")
|
||||
test_no_proxy("https", "sub.example.com", "example.com")
|
||||
test_no_proxy("https", "example.com", "example.com,example.org")
|
||||
test_no_proxy("https", "example.com", "example.org,example.com")
|
||||
|
||||
-- Edge cases
|
||||
|
||||
-- example.com should match .example.com in the no_proxy list (legacy behavior of wget)
|
||||
test_no_proxy("http", "example.com", ".example.com")
|
||||
|
||||
-- notexample.com should not match example.com in the no_proxy list (not a subdomain)
|
||||
test_no_proxy("http", "notexample.com", "example.com")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /lua
|
||||
--- response_body
|
||||
scheme: http, host: example.com, no_proxy: nil, proxy_uri: http://http_proxy.example.com
|
||||
scheme: http, host: example.com, no_proxy: *, proxy_uri: nil
|
||||
scheme: http, host: example.com, no_proxy: example.com, proxy_uri: nil
|
||||
scheme: http, host: sub.example.com, no_proxy: example.com, proxy_uri: nil
|
||||
scheme: http, host: example.com, no_proxy: example.com,example.org, proxy_uri: nil
|
||||
scheme: http, host: example.com, no_proxy: example.org,example.com, proxy_uri: nil
|
||||
scheme: https, host: example.com, no_proxy: nil, proxy_uri: http://https_proxy.example.com
|
||||
scheme: https, host: example.com, no_proxy: *, proxy_uri: nil
|
||||
scheme: https, host: example.com, no_proxy: example.com, proxy_uri: nil
|
||||
scheme: https, host: sub.example.com, no_proxy: example.com, proxy_uri: nil
|
||||
scheme: https, host: example.com, no_proxy: example.com,example.org, proxy_uri: nil
|
||||
scheme: https, host: example.com, no_proxy: example.org,example.com, proxy_uri: nil
|
||||
scheme: http, host: example.com, no_proxy: .example.com, proxy_uri: nil
|
||||
scheme: http, host: notexample.com, no_proxy: example.com, proxy_uri: http://http_proxy.example.com
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
|
||||
=== TEST 3: get_proxy_uri returns correct proxy URIs for http and https URIs
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /lua {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
|
||||
-- helper that configures the proxy opts as proived and checks what
|
||||
-- get_proxy_uri says for the given scheme / host pair
|
||||
local function test_get_proxy_uri(scheme, host, http_proxy, https_proxy)
|
||||
httpc:set_proxy_options({
|
||||
http_proxy = http_proxy,
|
||||
https_proxy = https_proxy
|
||||
})
|
||||
|
||||
local proxy_uri = httpc:get_proxy_uri(scheme, host)
|
||||
ngx.say(
|
||||
"scheme: ", scheme,
|
||||
", host: ", host,
|
||||
", http_proxy: ", http_proxy,
|
||||
", https_proxy: ", https_proxy,
|
||||
", proxy_uri: ", proxy_uri
|
||||
)
|
||||
end
|
||||
|
||||
-- http
|
||||
test_get_proxy_uri("http", "example.com", "http_proxy", "https_proxy")
|
||||
test_get_proxy_uri("http", "example.com", nil, "https_proxy")
|
||||
|
||||
-- https
|
||||
test_get_proxy_uri("https", "example.com", "http_proxy", "https_proxy")
|
||||
test_get_proxy_uri("https", "example.com", "http_proxy", nil)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /lua
|
||||
--- response_body
|
||||
scheme: http, host: example.com, http_proxy: http_proxy, https_proxy: https_proxy, proxy_uri: http_proxy
|
||||
scheme: http, host: example.com, http_proxy: nil, https_proxy: https_proxy, proxy_uri: nil
|
||||
scheme: https, host: example.com, http_proxy: http_proxy, https_proxy: https_proxy, proxy_uri: https_proxy
|
||||
scheme: https, host: example.com, http_proxy: http_proxy, https_proxy: nil, proxy_uri: nil
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
|
||||
=== TEST 4: request_uri uses http_proxy correctly for non-standard destination ports
|
||||
--- http_config
|
||||
lua_package_path "$TEST_NGINX_PWD/lib/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
resolver 8.8.8.8;
|
||||
server {
|
||||
listen *:8080;
|
||||
|
||||
location / {
|
||||
content_by_lua_block {
|
||||
ngx.print(ngx.req.raw_header())
|
||||
}
|
||||
}
|
||||
}
|
||||
--- config
|
||||
location /lua {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:set_proxy_options({
|
||||
http_proxy = "http://127.0.0.1:8080",
|
||||
https_proxy = "http://127.0.0.1:8080"
|
||||
})
|
||||
|
||||
-- request should go to the proxy server
|
||||
local res, err = httpc:request_uri("http://127.0.0.1:1234/target?a=1&b=2")
|
||||
|
||||
if not res then
|
||||
ngx.log(ngx.ERR, err)
|
||||
return
|
||||
end
|
||||
ngx.status = res.status
|
||||
ngx.say(res.body)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /lua
|
||||
--- response_body_like
|
||||
^GET http://127.0.0.1:1234/target\?a=1&b=2 HTTP/.+\r\nHost: 127.0.0.1:1234.+
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
|
||||
=== TEST 5: request_uri uses http_proxy correctly for standard destination port
|
||||
--- http_config
|
||||
lua_package_path "$TEST_NGINX_PWD/lib/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
resolver 8.8.8.8;
|
||||
server {
|
||||
listen *:8080;
|
||||
|
||||
location / {
|
||||
content_by_lua_block {
|
||||
ngx.print(ngx.req.raw_header())
|
||||
}
|
||||
}
|
||||
}
|
||||
--- config
|
||||
location /lua {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:set_proxy_options({
|
||||
http_proxy = "http://127.0.0.1:8080",
|
||||
https_proxy = "http://127.0.0.1:8080"
|
||||
})
|
||||
|
||||
-- request should go to the proxy server
|
||||
local res, err = httpc:request_uri("http://127.0.0.1/target?a=1&b=2")
|
||||
|
||||
if not res then
|
||||
ngx.log(ngx.ERR, err)
|
||||
return
|
||||
end
|
||||
|
||||
-- the proxy echoed the raw request header and we shall pass it onwards
|
||||
-- to the test harness
|
||||
ngx.status = res.status
|
||||
ngx.say(res.body)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /lua
|
||||
--- response_body_like
|
||||
^GET http://127.0.0.1/target\?a=1&b=2 HTTP/.+\r\nHost: 127.0.0.1.+
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
|
||||
=== TEST 6: request_uri makes a proper CONNECT request when proxying https resources
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /lua {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:set_proxy_options({
|
||||
http_proxy = "http://127.0.0.1:12345",
|
||||
https_proxy = "http://127.0.0.1:12345"
|
||||
})
|
||||
|
||||
-- Slight Hack: temporarily change the module global user agent to make it
|
||||
-- predictable for this test case
|
||||
local ua = http._USER_AGENT
|
||||
http._USER_AGENT = "test_ua"
|
||||
local res, err = httpc:request_uri("https://127.0.0.1/target?a=1&b=2")
|
||||
http._USER_AGENT = ua
|
||||
|
||||
if not err then
|
||||
-- The proxy request should fail as the TCP server listening returns
|
||||
-- 403 response. We cannot really test the success case here as that
|
||||
-- would require an actual reverse proxy to be implemented through
|
||||
-- the limited functionality we have available in the raw TCP sockets
|
||||
ngx.log(ngx.ERR, "unexpected success")
|
||||
return
|
||||
end
|
||||
|
||||
ngx.status = 403
|
||||
ngx.say(err)
|
||||
}
|
||||
}
|
||||
--- tcp_listen: 12345
|
||||
--- tcp_query eval
|
||||
qr/CONNECT 127.0.0.1:443 HTTP\/1.1\r\n.*Host: 127.0.0.1:443\r\n.*/s
|
||||
|
||||
# The reply cannot be successful or otherwise the client would start
|
||||
# to do a TLS handshake with the proxied host and that we cannot
|
||||
# do with these sockets
|
||||
--- tcp_reply
|
||||
HTTP/1.1 403 Forbidden
|
||||
Connection: close
|
||||
|
||||
--- request
|
||||
GET /lua
|
||||
--- error_code: 403
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
|
||||
=== TEST 7: request_uri uses http_proxy_authorization option
|
||||
--- http_config
|
||||
lua_package_path "$TEST_NGINX_PWD/lib/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
resolver 8.8.8.8;
|
||||
server {
|
||||
listen *:8080;
|
||||
|
||||
location / {
|
||||
content_by_lua_block {
|
||||
ngx.print(ngx.var.http_proxy_authorization or "no-header")
|
||||
}
|
||||
}
|
||||
}
|
||||
--- config
|
||||
location /lua {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:set_proxy_options({
|
||||
http_proxy = "http://127.0.0.1:8080",
|
||||
http_proxy_authorization = "Basic ZGVtbzp0ZXN0",
|
||||
https_proxy = "http://127.0.0.1:8080",
|
||||
https_proxy_authorization = "Basic ZGVtbzpwYXNz"
|
||||
})
|
||||
|
||||
-- request should go to the proxy server
|
||||
local res, err = httpc:request_uri("http://127.0.0.1/")
|
||||
if not res then
|
||||
ngx.log(ngx.ERR, err)
|
||||
return
|
||||
end
|
||||
|
||||
-- the proxy echoed the proxy authorization header
|
||||
-- to the test harness
|
||||
ngx.status = res.status
|
||||
ngx.say(res.body)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /lua
|
||||
--- response_body
|
||||
Basic ZGVtbzp0ZXN0
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
|
||||
=== TEST 8: request_uri uses https_proxy_authorization option
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /lua {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:set_proxy_options({
|
||||
http_proxy = "http://127.0.0.1:12345",
|
||||
http_proxy_authorization = "Basic ZGVtbzp0ZXN0",
|
||||
https_proxy = "http://127.0.0.1:12345",
|
||||
https_proxy_authorization = "Basic ZGVtbzpwYXNz"
|
||||
})
|
||||
|
||||
-- Slight Hack: temporarily change the module global user agent to make it
|
||||
-- predictable for this test case
|
||||
local ua = http._USER_AGENT
|
||||
http._USER_AGENT = "test_ua"
|
||||
local res, err = httpc:request_uri("https://127.0.0.1/target?a=1&b=2")
|
||||
http._USER_AGENT = ua
|
||||
|
||||
if not err then
|
||||
-- The proxy request should fail as the TCP server listening returns
|
||||
-- 403 response. We cannot really test the success case here as that
|
||||
-- would require an actual reverse proxy to be implemented through
|
||||
-- the limited functionality we have available in the raw TCP sockets
|
||||
ngx.log(ngx.ERR, "unexpected success")
|
||||
return
|
||||
end
|
||||
|
||||
ngx.status = 403
|
||||
ngx.say(err)
|
||||
}
|
||||
}
|
||||
--- tcp_listen: 12345
|
||||
--- tcp_query eval
|
||||
qr/CONNECT 127.0.0.1:443 HTTP\/1.1\r\n.*Proxy-Authorization: Basic ZGVtbzpwYXNz\r\n.*/s
|
||||
|
||||
# The reply cannot be successful or otherwise the client would start
|
||||
# to do a TLS handshake with the proxied host and that we cannot
|
||||
# do with these sockets
|
||||
--- tcp_reply
|
||||
HTTP/1.1 403 Forbidden
|
||||
Connection: close
|
||||
|
||||
--- request
|
||||
GET /lua
|
||||
--- error_code: 403
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
|
||||
=== TEST 9: request_uri does not use http_proxy_authorization option when overridden
|
||||
--- http_config
|
||||
lua_package_path "$TEST_NGINX_PWD/lib/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
resolver 8.8.8.8;
|
||||
server {
|
||||
listen *:8080;
|
||||
|
||||
location / {
|
||||
content_by_lua_block {
|
||||
ngx.print(ngx.var.http_proxy_authorization or "no-header")
|
||||
}
|
||||
}
|
||||
}
|
||||
--- config
|
||||
location /lua {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:set_proxy_options({
|
||||
http_proxy = "http://127.0.0.1:8080",
|
||||
http_proxy_authorization = "Basic ZGVtbzp0ZXN0",
|
||||
https_proxy = "http://127.0.0.1:8080",
|
||||
https_proxy_authorization = "Basic ZGVtbzpwYXNz"
|
||||
})
|
||||
|
||||
-- request should go to the proxy server
|
||||
local res, err = httpc:request_uri("http://127.0.0.1/", {
|
||||
headers = {
|
||||
["Proxy-Authorization"] = "Basic ZGVtbzp3b3Jk"
|
||||
}
|
||||
})
|
||||
if not res then
|
||||
ngx.log(ngx.ERR, err)
|
||||
return
|
||||
end
|
||||
|
||||
-- the proxy echoed the proxy authorization header
|
||||
-- to the test harness
|
||||
ngx.status = res.status
|
||||
ngx.say(res.body)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /lua
|
||||
--- response_body
|
||||
Basic ZGVtbzp3b3Jk
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
|
||||
=== TEST 10: request_uri does not use https_proxy_authorization option when overridden
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /lua {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
httpc:set_proxy_options({
|
||||
http_proxy = "http://127.0.0.1:12345",
|
||||
http_proxy_authorization = "Basic ZGVtbzp0ZXN0",
|
||||
https_proxy = "http://127.0.0.1:12345",
|
||||
https_proxy_authorization = "Basic ZGVtbzpwYXNz"
|
||||
})
|
||||
|
||||
-- Slight Hack: temporarily change the module global user agent to make it
|
||||
-- predictable for this test case
|
||||
local ua = http._USER_AGENT
|
||||
http._USER_AGENT = "test_ua"
|
||||
local res, err = httpc:request_uri("https://127.0.0.1/target?a=1&b=2", {
|
||||
headers = {
|
||||
["Proxy-Authorization"] = "Basic ZGVtbzp3b3Jk"
|
||||
}
|
||||
})
|
||||
http._USER_AGENT = ua
|
||||
|
||||
if not err then
|
||||
-- The proxy request should fail as the TCP server listening returns
|
||||
-- 403 response. We cannot really test the success case here as that
|
||||
-- would require an actual reverse proxy to be implemented through
|
||||
-- the limited functionality we have available in the raw TCP sockets
|
||||
ngx.log(ngx.ERR, "unexpected success")
|
||||
return
|
||||
end
|
||||
|
||||
ngx.status = 403
|
||||
ngx.say(err)
|
||||
}
|
||||
}
|
||||
--- tcp_listen: 12345
|
||||
--- tcp_query eval
|
||||
qr/CONNECT 127.0.0.1:443 HTTP\/1.1\r\n.*Proxy-Authorization: Basic ZGVtbzp3b3Jk\r\n.*/s
|
||||
|
||||
# The reply cannot be successful or otherwise the client would start
|
||||
# to do a TLS handshake with the proxied host and that we cannot
|
||||
# do with these sockets
|
||||
--- tcp_reply
|
||||
HTTP/1.1 403 Forbidden
|
||||
Connection: close
|
||||
|
||||
--- request
|
||||
GET /lua
|
||||
--- error_code: 403
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
58
src/deps/src/lua-resty-http/t/17-deprecated.t
vendored
58
src/deps/src/lua-resty-http/t/17-deprecated.t
vendored
|
|
@ -1,58 +0,0 @@
|
|||
use Test::Nginx::Socket 'no_plan';
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
$ENV{TEST_NGINX_PWD} ||= $pwd;
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
resolver 8.8.8.8;
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
}
|
||||
};
|
||||
|
||||
no_long_string();
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
=== TEST 1: Old connect syntax still works
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /a {
|
||||
content_by_lua_block {
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
local ok, err = httpc:connect("127.0.0.1", ngx.var.server_port)
|
||||
assert(ok, err)
|
||||
|
||||
local res, err = httpc:request{
|
||||
path = "/b"
|
||||
}
|
||||
|
||||
ngx.status = res.status
|
||||
ngx.print(res:read_body())
|
||||
|
||||
httpc:close()
|
||||
}
|
||||
}
|
||||
location = /b {
|
||||
echo "OK";
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
OK
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
--- error_log
|
||||
[debug]
|
||||
157
src/deps/src/lua-resty-http/t/18-parse_uri.t
vendored
157
src/deps/src/lua-resty-http/t/18-parse_uri.t
vendored
|
|
@ -1,157 +0,0 @@
|
|||
use Test::Nginx::Socket 'no_plan';
|
||||
use Cwd qw(cwd);
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
|
||||
error_log logs/error.log debug;
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
}
|
||||
};
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
=== TEST 1: Parse URI errors if malformed
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require("resty.http").new()
|
||||
local parts, err = http:parse_uri("http:///example.com")
|
||||
if not parts then ngx.say(err) end
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
bad uri: http:///example.com
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 2: Parse URI fills in defaults correctly
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require("resty.http").new()
|
||||
|
||||
local function test_uri(uri)
|
||||
local scheme, host, port, path, query = unpack(http:parse_uri(uri, false))
|
||||
ngx.say("scheme: ", scheme, ", host: ", host, ", port: ", port, ", path: ", path, ", query: ", query)
|
||||
end
|
||||
|
||||
test_uri("http://example.com")
|
||||
test_uri("http://example.com/")
|
||||
test_uri("https://example.com/foo/bar")
|
||||
test_uri("https://example.com/foo/bar?a=1&b=2")
|
||||
test_uri("http://example.com?a=1&b=2")
|
||||
test_uri("//example.com")
|
||||
test_uri("//example.com?a=1&b=2")
|
||||
test_uri("//example.com/foo/bar?a=1&b=2")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
scheme: http, host: example.com, port: 80, path: /, query:
|
||||
scheme: http, host: example.com, port: 80, path: /, query:
|
||||
scheme: https, host: example.com, port: 443, path: /foo/bar, query:
|
||||
scheme: https, host: example.com, port: 443, path: /foo/bar, query: a=1&b=2
|
||||
scheme: http, host: example.com, port: 80, path: /, query: a=1&b=2
|
||||
scheme: http, host: example.com, port: 80, path: /, query:
|
||||
scheme: http, host: example.com, port: 80, path: /, query: a=1&b=2
|
||||
scheme: http, host: example.com, port: 80, path: /foo/bar, query: a=1&b=2
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 3: Parse URI fills in defaults correctly, using backwards compatible mode
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require("resty.http").new()
|
||||
|
||||
local function test_uri(uri)
|
||||
local scheme, host, port, path, query = unpack(http:parse_uri(uri))
|
||||
ngx.say("scheme: ", scheme, ", host: ", host, ", port: ", port, ", path: ", path)
|
||||
end
|
||||
|
||||
test_uri("http://example.com")
|
||||
test_uri("http://example.com/")
|
||||
test_uri("https://example.com/foo/bar")
|
||||
test_uri("https://example.com/foo/bar?a=1&b=2")
|
||||
test_uri("http://example.com?a=1&b=2")
|
||||
test_uri("//example.com")
|
||||
test_uri("//example.com?a=1&b=2")
|
||||
test_uri("//example.com/foo/bar?a=1&b=2")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
scheme: http, host: example.com, port: 80, path: /
|
||||
scheme: http, host: example.com, port: 80, path: /
|
||||
scheme: https, host: example.com, port: 443, path: /foo/bar
|
||||
scheme: https, host: example.com, port: 443, path: /foo/bar?a=1&b=2
|
||||
scheme: http, host: example.com, port: 80, path: /?a=1&b=2
|
||||
scheme: http, host: example.com, port: 80, path: /
|
||||
scheme: http, host: example.com, port: 80, path: /?a=1&b=2
|
||||
scheme: http, host: example.com, port: 80, path: /foo/bar?a=1&b=2
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 4: IPv6 notation
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location = /a {
|
||||
content_by_lua '
|
||||
local http = require("resty.http").new()
|
||||
|
||||
local function test_uri(uri)
|
||||
local scheme, host, port, path, query = unpack(http:parse_uri(uri, false))
|
||||
ngx.say("scheme: ", scheme, ", host: ", host, ", port: ", port, ", path: ", path, ", query: ", query)
|
||||
end
|
||||
|
||||
test_uri("http://[::1]")
|
||||
test_uri("http://[::1]/")
|
||||
test_uri("https://[::1]/foo/bar")
|
||||
test_uri("https://[::1]/foo/bar?a=1&b=2")
|
||||
test_uri("http://[::1]?a=1&b=2")
|
||||
test_uri("//[0:0:0:0:0:0:0:0]")
|
||||
test_uri("//[0:0:0:0:0:0:0:0]?a=1&b=2")
|
||||
test_uri("//[0:0:0:0:0:0:0:0]/foo/bar?a=1&b=2")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /a
|
||||
--- response_body
|
||||
scheme: http, host: [::1], port: 80, path: /, query:
|
||||
scheme: http, host: [::1], port: 80, path: /, query:
|
||||
scheme: https, host: [::1], port: 443, path: /foo/bar, query:
|
||||
scheme: https, host: [::1], port: 443, path: /foo/bar, query: a=1&b=2
|
||||
scheme: http, host: [::1], port: 80, path: /, query: a=1&b=2
|
||||
scheme: http, host: [0:0:0:0:0:0:0:0], port: 80, path: /, query:
|
||||
scheme: http, host: [0:0:0:0:0:0:0:0], port: 80, path: /, query: a=1&b=2
|
||||
scheme: http, host: [0:0:0:0:0:0:0:0], port: 80, path: /foo/bar, query: a=1&b=2
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
|
@ -1,136 +0,0 @@
|
|||
use Test::Nginx::Socket::Lua 'no_plan';
|
||||
use Cwd qw(abs_path realpath);
|
||||
use File::Basename;
|
||||
|
||||
$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
|
||||
$ENV{TEST_NGINX_CERT_DIR} ||= dirname(realpath(abs_path(__FILE__)));
|
||||
$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
my $realpath = realpath();
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$realpath/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
|
||||
|
||||
init_by_lua_block {
|
||||
if $ENV{TEST_COVERAGE} == 1 then
|
||||
jit.off()
|
||||
require("luacov.runner").init()
|
||||
end
|
||||
|
||||
TEST_SERVER_SOCK = "unix:/$ENV{TEST_NGINX_HTML_DIR}/nginx.sock"
|
||||
|
||||
num_handshakes = 0
|
||||
}
|
||||
|
||||
server {
|
||||
listen unix:$ENV{TEST_NGINX_HTML_DIR}/nginx.sock ssl;
|
||||
server_name example.com;
|
||||
ssl_certificate $ENV{TEST_NGINX_CERT_DIR}/cert/test.crt;
|
||||
ssl_certificate_key $ENV{TEST_NGINX_CERT_DIR}/cert/test.key;
|
||||
ssl_session_tickets off;
|
||||
|
||||
server_tokens off;
|
||||
}
|
||||
};
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: connect returns session userdata
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
server_tokens off;
|
||||
resolver $TEST_NGINX_RESOLVER ipv6=off;
|
||||
lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
|
||||
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local httpc = assert(require("resty.http").new())
|
||||
local ok, err, session = assert(httpc:connect {
|
||||
scheme = "https",
|
||||
host = TEST_SERVER_SOCK,
|
||||
})
|
||||
|
||||
assert(type(session) == "userdata" or type(session) == "cdata", "expected session to be userdata or cdata")
|
||||
assert(httpc:close())
|
||||
}
|
||||
}
|
||||
|
||||
--- request
|
||||
GET /t
|
||||
--- no_error_log
|
||||
[error]
|
||||
[alert]
|
||||
|
||||
|
||||
=== TEST 2: ssl_reused_session false does not return session userdata
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
server_tokens off;
|
||||
resolver $TEST_NGINX_RESOLVER ipv6=off;
|
||||
lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
|
||||
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local httpc = assert(require("resty.http").new())
|
||||
local ok, err, session = assert(httpc:connect {
|
||||
scheme = "https",
|
||||
host = TEST_SERVER_SOCK,
|
||||
ssl_reused_session = false,
|
||||
})
|
||||
|
||||
assert(type(session) == "boolean", "expected session to be a boolean")
|
||||
assert(session == true, "expected session to be true")
|
||||
assert(httpc:close())
|
||||
}
|
||||
}
|
||||
|
||||
--- request
|
||||
GET /t
|
||||
--- no_error_log
|
||||
[error]
|
||||
[alert]
|
||||
|
||||
|
||||
=== TEST 3: ssl_reused_session accepts userdata
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
server_tokens off;
|
||||
resolver $TEST_NGINX_RESOLVER ipv6=off;
|
||||
lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
|
||||
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local httpc = assert(require("resty.http").new())
|
||||
local ok, err, session = assert(httpc:connect {
|
||||
scheme = "https",
|
||||
host = TEST_SERVER_SOCK,
|
||||
})
|
||||
|
||||
assert(type(session) == "userdata" or type(session) == "cdata", "expected session to be userdata or cdata")
|
||||
|
||||
local httpc2 = assert(require("resty.http").new())
|
||||
local ok, err, session2 = assert(httpc2:connect {
|
||||
scheme = "https",
|
||||
host = TEST_SERVER_SOCK,
|
||||
ssl_reused_session = session,
|
||||
})
|
||||
|
||||
assert(type(session2) == "userdata" or type(session2) == "cdata", "expected session2 to be userdata or cdata")
|
||||
|
||||
assert(httpc:close())
|
||||
assert(httpc2:close())
|
||||
}
|
||||
}
|
||||
|
||||
--- request
|
||||
GET /t
|
||||
--- no_error_log
|
||||
[error]
|
||||
[alert]
|
||||
316
src/deps/src/lua-resty-http/t/20-mtls.t
vendored
316
src/deps/src/lua-resty-http/t/20-mtls.t
vendored
|
|
@ -1,316 +0,0 @@
|
|||
use Test::Nginx::Socket::Lua 'no_plan';
|
||||
|
||||
|
||||
#$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
|
||||
#$ENV{TEST_COVERAGE} ||= 0;
|
||||
|
||||
log_level 'debug';
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
sub read_file {
|
||||
my $infile = shift;
|
||||
open my $in, $infile
|
||||
or die "cannot open $infile for reading: $!";
|
||||
my $cert = do { local $/; <$in> };
|
||||
close $in;
|
||||
$cert;
|
||||
}
|
||||
|
||||
our $MTLSCA = read_file("t/cert/mtls_ca.crt");
|
||||
our $MTLSClient = read_file("t/cert/mtls_client.crt");
|
||||
our $MTLSClientKey = read_file("t/cert/mtls_client.key");
|
||||
our $TestCert = read_file("t/cert/test.crt");
|
||||
our $TestKey = read_file("t/cert/test.key");
|
||||
|
||||
our $HtmlDir = html_dir;
|
||||
|
||||
use Cwd qw(cwd);
|
||||
my $pwd = cwd();
|
||||
|
||||
our $mtls_http_config = <<"_EOC_";
|
||||
lua_package_path "$pwd/lib/?.lua;/usr/local/share/lua/5.1/?.lua;;";
|
||||
server {
|
||||
listen unix:$::HtmlDir/mtls.sock ssl;
|
||||
|
||||
ssl_certificate $::HtmlDir/test.crt;
|
||||
ssl_certificate_key $::HtmlDir/test.key;
|
||||
ssl_client_certificate $::HtmlDir/mtls_ca.crt;
|
||||
ssl_verify_client on;
|
||||
server_tokens off;
|
||||
server_name example.com;
|
||||
|
||||
location / {
|
||||
echo -n "hello, \$ssl_client_s_dn";
|
||||
}
|
||||
}
|
||||
_EOC_
|
||||
|
||||
our $mtls_user_files = <<"_EOC_";
|
||||
>>> mtls_ca.crt
|
||||
$::MTLSCA
|
||||
>>> mtls_client.key
|
||||
$::MTLSClientKey
|
||||
>>> mtls_client.crt
|
||||
$::MTLSClient
|
||||
>>> test.crt
|
||||
$::TestCert
|
||||
>>> test.key
|
||||
$::TestKey
|
||||
_EOC_
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: Connection fails during handshake without client cert and key
|
||||
--- http_config eval: $::mtls_http_config
|
||||
--- config eval
|
||||
"
|
||||
lua_ssl_trusted_certificate $::HtmlDir/test.crt;
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local httpc = assert(require('resty.http').new())
|
||||
|
||||
local ok, err = httpc:connect {
|
||||
scheme = 'https',
|
||||
host = 'unix:$::HtmlDir/mtls.sock',
|
||||
}
|
||||
|
||||
if ok and not err then
|
||||
local res, err = assert(httpc:request {
|
||||
method = 'GET',
|
||||
path = '/',
|
||||
headers = {
|
||||
['Host'] = 'example.com',
|
||||
},
|
||||
})
|
||||
|
||||
ngx.status = res.status -- expect 400
|
||||
end
|
||||
|
||||
httpc:close()
|
||||
}
|
||||
}
|
||||
"
|
||||
--- user_files eval: $::mtls_user_files
|
||||
--- request
|
||||
GET /t
|
||||
--- error_code: 400
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
|
||||
|
||||
=== TEST 2: Connection fails during handshake with not priv_key
|
||||
--- http_config eval: $::mtls_http_config
|
||||
--- config eval
|
||||
"
|
||||
lua_ssl_trusted_certificate $::HtmlDir/test.crt;
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local f = assert(io.open('$::HtmlDir/mtls_client.crt'))
|
||||
local cert_data = f:read('*a')
|
||||
f:close()
|
||||
|
||||
local ssl = require('ngx.ssl')
|
||||
|
||||
local cert = assert(ssl.parse_pem_cert(cert_data))
|
||||
|
||||
local httpc = assert(require('resty.http').new())
|
||||
|
||||
local ok, err = httpc:connect {
|
||||
scheme = 'https',
|
||||
host = 'unix:$::HtmlDir/mtls.sock',
|
||||
ssl_client_cert = cert,
|
||||
ssl_client_priv_key = 'foo',
|
||||
}
|
||||
|
||||
if ok and not err then
|
||||
local res, err = assert(httpc:request {
|
||||
method = 'GET',
|
||||
path = '/',
|
||||
headers = {
|
||||
['Host'] = 'example.com',
|
||||
},
|
||||
})
|
||||
|
||||
ngx.say(res:read_body())
|
||||
|
||||
else
|
||||
ngx.say('failed to connect: ' .. (err or ''))
|
||||
end
|
||||
|
||||
httpc:close()
|
||||
}
|
||||
}
|
||||
"
|
||||
--- user_files eval: $::mtls_user_files
|
||||
--- request
|
||||
GET /t
|
||||
--- error_code: 200
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
--- response_body
|
||||
failed to connect: bad ssl_client_priv_key: cdata expected, got string
|
||||
--- skip_nginx
|
||||
4: < 1.21.4
|
||||
|
||||
|
||||
=== TEST 3: Connection succeeds with client cert and key.
|
||||
--- http_config eval: $::mtls_http_config
|
||||
--- config eval
|
||||
"
|
||||
lua_ssl_trusted_certificate $::HtmlDir/test.crt;
|
||||
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local f = assert(io.open('$::HtmlDir/mtls_client.crt'))
|
||||
local cert_data = f:read('*a')
|
||||
f:close()
|
||||
|
||||
f = assert(io.open('$::HtmlDir/mtls_client.key'))
|
||||
local key_data = f:read('*a')
|
||||
f:close()
|
||||
|
||||
local ssl = require('ngx.ssl')
|
||||
|
||||
local cert = assert(ssl.parse_pem_cert(cert_data))
|
||||
local key = assert(ssl.parse_pem_priv_key(key_data))
|
||||
|
||||
local httpc = assert(require('resty.http').new())
|
||||
|
||||
local ok, err = httpc:connect {
|
||||
scheme = 'https',
|
||||
host = 'unix:$::HtmlDir/mtls.sock',
|
||||
ssl_client_cert = cert,
|
||||
ssl_client_priv_key = key,
|
||||
}
|
||||
|
||||
if ok and not err then
|
||||
local res, err = assert(httpc:request {
|
||||
method = 'GET',
|
||||
path = '/',
|
||||
headers = {
|
||||
['Host'] = 'example.com',
|
||||
},
|
||||
})
|
||||
|
||||
ngx.say(res:read_body())
|
||||
end
|
||||
|
||||
httpc:close()
|
||||
}
|
||||
}
|
||||
"
|
||||
--- user_files eval: $::mtls_user_files
|
||||
--- request
|
||||
GET /t
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
--- response_body
|
||||
hello, CN=foo@example.com,O=OpenResty,ST=California,C=US
|
||||
--- skip_nginx
|
||||
4: < 1.21.4
|
||||
|
||||
=== TEST 4: users with different client certs should not share the same pool.
|
||||
--- http_config eval: $::mtls_http_config
|
||||
--- config eval
|
||||
"
|
||||
lua_ssl_trusted_certificate $::HtmlDir/test.crt;
|
||||
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local f = assert(io.open('$::HtmlDir/mtls_client.crt'))
|
||||
local cert_data = f:read('*a')
|
||||
f:close()
|
||||
|
||||
f = assert(io.open('$::HtmlDir/mtls_client.key'))
|
||||
local key_data = f:read('*a')
|
||||
f:close()
|
||||
|
||||
local ssl = require('ngx.ssl')
|
||||
|
||||
local cert = assert(ssl.parse_pem_cert(cert_data))
|
||||
local key = assert(ssl.parse_pem_priv_key(key_data))
|
||||
|
||||
f = assert(io.open('$::HtmlDir/test.crt'))
|
||||
local invalid_cert_data = f:read('*a')
|
||||
f:close()
|
||||
|
||||
f = assert(io.open('$::HtmlDir/test.key'))
|
||||
local invalid_key_data = f:read('*a')
|
||||
f:close()
|
||||
|
||||
local invalid_cert = assert(ssl.parse_pem_cert(invalid_cert_data))
|
||||
local invalid_key = assert(ssl.parse_pem_priv_key(invalid_key_data))
|
||||
|
||||
local httpc = assert(require('resty.http').new())
|
||||
|
||||
local ok, err = httpc:connect {
|
||||
scheme = 'https',
|
||||
host = 'unix:$::HtmlDir/mtls.sock',
|
||||
ssl_client_cert = cert,
|
||||
ssl_client_priv_key = key,
|
||||
}
|
||||
|
||||
if ok and not err then
|
||||
local res, err = assert(httpc:request {
|
||||
method = 'GET',
|
||||
path = '/',
|
||||
headers = {
|
||||
['Host'] = 'example.com',
|
||||
},
|
||||
})
|
||||
|
||||
ngx.say(res:read_body())
|
||||
end
|
||||
|
||||
httpc:set_keepalive()
|
||||
|
||||
local httpc = assert(require('resty.http').new())
|
||||
|
||||
local ok, err = httpc:connect {
|
||||
scheme = 'https',
|
||||
host = 'unix:$::HtmlDir/mtls.sock',
|
||||
ssl_client_cert = invalid_cert,
|
||||
ssl_client_priv_key = invalid_key,
|
||||
}
|
||||
|
||||
ngx.say(httpc:get_reused_times())
|
||||
ngx.say(ok)
|
||||
ngx.say(err)
|
||||
|
||||
if ok and not err then
|
||||
local res, err = assert(httpc:request {
|
||||
method = 'GET',
|
||||
path = '/',
|
||||
headers = {
|
||||
['Host'] = 'example.com',
|
||||
},
|
||||
})
|
||||
|
||||
ngx.say(res.status) -- expect 400
|
||||
end
|
||||
|
||||
httpc:close()
|
||||
}
|
||||
}
|
||||
"
|
||||
--- user_files eval: $::mtls_user_files
|
||||
--- request
|
||||
GET /t
|
||||
--- no_error_log
|
||||
[error]
|
||||
[warn]
|
||||
--- response_body
|
||||
hello, CN=foo@example.com,O=OpenResty,ST=California,C=US
|
||||
0
|
||||
true
|
||||
nil
|
||||
400
|
||||
--- skip_nginx
|
||||
4: < 1.21.4
|
||||
33
src/deps/src/lua-resty-http/t/cert/mtls_ca.crt
vendored
33
src/deps/src/lua-resty-http/t/cert/mtls_ca.crt
vendored
|
|
@ -1,33 +0,0 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIFpTCCA42gAwIBAgIUfTh89NyxxmbVwNZ/YFddssWc+WkwDQYJKoZIhvcNAQEL
|
||||
BQAwWjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExEjAQBgNVBAoM
|
||||
CU9wZW5SZXN0eTEiMCAGA1UEAwwZT3BlblJlc3R5IFRlc3RpbmcgUm9vdCBDQTAe
|
||||
Fw0xOTA5MTMyMjI4MTJaFw0zOTA5MDgyMjI4MTJaMFoxCzAJBgNVBAYTAlVTMRMw
|
||||
EQYDVQQIDApDYWxpZm9ybmlhMRIwEAYDVQQKDAlPcGVuUmVzdHkxIjAgBgNVBAMM
|
||||
GU9wZW5SZXN0eSBUZXN0aW5nIFJvb3QgQ0EwggIiMA0GCSqGSIb3DQEBAQUAA4IC
|
||||
DwAwggIKAoICAQDcMg2DeV8z+0E2ZiXUax111lKzhAbMCK0RJlV9tAi+YdcsDR/t
|
||||
zvvAZNGONUoewUuz/7E88oweh+Xi1GJtvd0DjB70y7tgpf5PUXovstWVwy7s5jZo
|
||||
kgn62yi9ZOOZpjwnYTBviirtRTnZRwkzL6wF0xMyJjAbKBJuPMrMiyFdh82lt7wI
|
||||
NS4mhyEdM0UiVVxfC2uzsddTOcOJURfGbW7UZm4Xohzq4QZ8geQj2OT5YTqw7dZ7
|
||||
Xxre5H7IcNcAh+vIk5SEBV1WE+S5MnFly7gaLYNc49OSfz5Hcpv59Vr+4bZ+olbW
|
||||
nQ/uU8BQovtkW6pjuT8nC4OKs2e8osoAZuk0rFS1uC501C+yES48mzaU8ttAidu6
|
||||
nb/JgsdkrnJQeTc5rAoER4M2ne5kqtEXN8wzf3/sazo2PLywbfrUXUTV6kJilrGr
|
||||
RkBN+fr6HTBkf+ooQMBOQPTojUdwbR86CLCyiJov2bzmBfGcOgSakv59S+uvUZFp
|
||||
FLTiahuzLfcgYsG3UKQA47pYlNdUqP8vCCaf1nwmqjx2KS3Z/YFnO/gQgtY+f0Bh
|
||||
UpnUDv+zBxpVFfVCyxByEsDPdwDkqLSwB6+YZINl36S48iXpoPhNXIYmO6GnhNWV
|
||||
k2/RyCDTxEO+MbXHVg6iyIVHJWth7m18vl4uuSK/LbJHV9Q9Z7G99DQ0NwIDAQAB
|
||||
o2MwYTAdBgNVHQ4EFgQUuoo+ehdlDFcQU+j5qONMKh0NtFQwHwYDVR0jBBgwFoAU
|
||||
uoo+ehdlDFcQU+j5qONMKh0NtFQwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8E
|
||||
BAMCAYYwDQYJKoZIhvcNAQELBQADggIBAM7c9q41K8306lfAVLqtbtaeETy+xxYG
|
||||
XE2HfFW1IuukrXQ8d/JH4stL/HcHJzzhHPf5p3ja3Snu9zPmTk3pgUPDYPZf57tR
|
||||
NCqwxjn6blwXWlzQqSavto9KAx3IWHuj0OTrZz/a1KPb9NGvatBhgthyRCRTbvhL
|
||||
OA5tveuYSHb724cp3NZ1xaTQmDZsSgHCoCJ/7RnlbcJ7RsKCOzCWNFRomH410vdv
|
||||
TajkUBlEC4OC1RIvxuVePHHb1ogbbe93SA/9mzw/E5SfoeF3mvByN4Ay8awXbNlH
|
||||
26RfuIdGc4fZRc/87s4yPwhYScZBG+pHO0gn42E0FyiG6Jp3rhHMH5Sa2hNlPMpn
|
||||
hYMaA6zQI4n/3AeFNM0VGxA+Yg/Al2WpXEJARrZqMW/qcrdMcPj5WeY6Tb6er04S
|
||||
kfImwhMIajl3nNc9tHoad8r2VuMWMltH/dnWuEdo+pPdIY3fdJdyQeoLQDDLEQwL
|
||||
AYrFy4uzKfQogfQBIHRdIMZTJh5v3mAFDpK59I5yzSt1GtUnFMC5MVOg+LbOo5UW
|
||||
FCtwaW5EZiTszmakvvWMMZe9HwZMYNCeSGGtiPA/GA2zNci/n2TEcB11HgiY52y2
|
||||
E/40nS61oL81zMwhV7l5psgJxQ2ORsKRJPHjADwvwh3xyCEJgVyBRCDX7J3PpAUO
|
||||
79DprjVU8t7p
|
||||
-----END CERTIFICATE-----
|
||||
111
src/deps/src/lua-resty-http/t/cert/mtls_client.crt
vendored
111
src/deps/src/lua-resty-http/t/cert/mtls_client.crt
vendored
|
|
@ -1,111 +0,0 @@
|
|||
Certificate:
|
||||
Data:
|
||||
Version: 3 (0x2)
|
||||
Serial Number: 4096 (0x1000)
|
||||
Signature Algorithm: sha256WithRSAEncryption
|
||||
Issuer: C=US, ST=California, O=OpenResty, CN=OpenResty Testing Root CA
|
||||
Validity
|
||||
Not Before: Sep 13 22:30:49 2019 GMT
|
||||
Not After : Sep 10 22:30:49 2029 GMT
|
||||
Subject: C=US, ST=California, O=OpenResty, CN=foo@example.com
|
||||
Subject Public Key Info:
|
||||
Public Key Algorithm: rsaEncryption
|
||||
RSA Public-Key: (2048 bit)
|
||||
Modulus:
|
||||
00:d0:8c:1e:2c:25:7f:00:9d:8a:3d:8a:f3:b5:1d:
|
||||
6b:24:f5:ac:35:7d:cd:b7:d0:af:db:88:7c:ee:82:
|
||||
46:16:47:f3:43:08:a1:04:6e:0d:3e:ce:69:fa:d5:
|
||||
89:14:82:20:f1:47:f2:38:c8:ab:ea:2f:1e:f0:15:
|
||||
04:c0:f4:8b:3c:c3:d4:78:56:87:4c:f1:70:ac:11:
|
||||
86:2e:c4:6a:6d:10:84:27:81:ca:2a:8b:85:3e:62:
|
||||
13:5e:40:6c:19:e4:49:3d:f3:de:aa:e8:5e:11:a1:
|
||||
f2:66:83:6a:40:d1:34:c5:bf:b8:cb:97:7c:6a:ea:
|
||||
46:bf:17:be:32:8d:a8:31:56:e5:8b:6d:08:03:d0:
|
||||
44:69:b9:af:1e:15:1d:a5:64:9e:12:84:83:db:d9:
|
||||
c6:71:90:3b:c2:7b:41:21:57:af:70:15:0b:56:59:
|
||||
21:a6:4e:46:71:66:90:f1:ef:bc:b2:48:f9:8b:ea:
|
||||
e5:72:4a:ba:4a:ae:2d:74:0b:33:03:f6:2e:47:0f:
|
||||
56:a4:00:e8:1e:62:cb:b8:af:9c:98:1a:89:7c:d0:
|
||||
a3:7a:5a:e1:84:50:64:e4:5d:a5:70:a4:69:54:c4:
|
||||
f4:76:44:a2:be:1b:ef:dc:a3:d8:1d:0d:30:a2:d4:
|
||||
79:fb:39:76:ab:b7:18:f2:f7:92:f8:81:83:94:b8:
|
||||
11:b1
|
||||
Exponent: 65537 (0x10001)
|
||||
X509v3 extensions:
|
||||
X509v3 Basic Constraints:
|
||||
CA:FALSE
|
||||
Netscape Cert Type:
|
||||
SSL Client, S/MIME
|
||||
Netscape Comment:
|
||||
OpenSSL Generated Client Certificate
|
||||
X509v3 Subject Key Identifier:
|
||||
D2:E4:F5:21:1C:17:A4:FF:13:F4:1A:28:A8:A7:DC:C6:DE:89:A0:31
|
||||
X509v3 Authority Key Identifier:
|
||||
keyid:BA:8A:3E:7A:17:65:0C:57:10:53:E8:F9:A8:E3:4C:2A:1D:0D:B4:54
|
||||
|
||||
X509v3 Key Usage: critical
|
||||
Digital Signature, Non Repudiation, Key Encipherment
|
||||
X509v3 Extended Key Usage:
|
||||
TLS Web Client Authentication, E-mail Protection
|
||||
X509v3 Subject Alternative Name:
|
||||
email:foo@example.com, email:bar@example.com
|
||||
Signature Algorithm: sha256WithRSAEncryption
|
||||
47:77:51:37:00:f7:28:da:c4:d9:4e:38:c4:ec:ea:24:c9:83:
|
||||
36:4c:90:93:a7:b2:2b:10:bf:75:df:0b:72:d8:e7:4f:4f:68:
|
||||
e5:32:2f:35:89:17:95:5c:bb:43:fc:70:89:46:08:43:61:ac:
|
||||
41:62:84:01:94:88:d1:dc:8a:bd:30:2c:18:eb:51:79:0b:b7:
|
||||
1b:b6:49:df:c9:85:55:f6:73:9f:b7:83:99:52:23:fe:e6:bd:
|
||||
09:da:90:b9:e2:9b:68:c4:df:bd:fe:23:94:55:34:be:0d:7d:
|
||||
84:0c:53:69:2a:0f:3c:47:68:34:3f:2a:3f:89:3f:3e:d3:26:
|
||||
ce:b7:58:bc:d0:6f:ee:f8:bd:5d:c6:48:ae:a0:6c:1f:6d:e0:
|
||||
66:93:7d:db:3c:07:e6:15:ae:aa:e3:d0:3d:ef:04:b6:dd:53:
|
||||
16:93:61:70:e9:af:c0:e9:1d:ff:2b:e5:0a:03:56:48:3f:1c:
|
||||
dc:fe:1b:a6:6d:f6:54:ab:41:e5:3b:5b:ab:f5:81:10:46:26:
|
||||
bb:ea:d7:0e:33:b1:5e:30:4d:81:86:63:9a:4a:4f:1e:44:b9:
|
||||
c2:c6:08:4e:da:fa:3a:55:da:96:7c:01:f6:d5:e8:3b:ba:e9:
|
||||
31:3b:1c:51:39:1a:59:f0:e0:c7:17:2e:f6:18:9d:ec:a7:48:
|
||||
30:b8:4c:6d:e5:4a:4f:43:41:cb:0e:6b:ac:ad:87:44:90:76:
|
||||
85:23:2b:eb:8f:97:4b:22:13:60:20:3a:37:a4:dc:74:7d:85:
|
||||
3d:a1:f5:1a:03:f6:d5:78:c7:bc:9b:09:f2:c8:05:27:43:2a:
|
||||
ac:50:21:3a:ee:83:2d:db:02:6f:c7:91:de:63:d6:36:7d:7a:
|
||||
9f:1f:fb:48:62:f4:fb:8e:3a:ea:61:9b:3c:03:f9:f8:a5:df:
|
||||
1b:02:14:2c:de:e6:e3:47:d2:44:65:94:1a:c6:e1:fd:ba:8d:
|
||||
b6:f8:93:a9:46:46:26:79:b0:bf:57:a8:a2:20:66:56:7e:c9:
|
||||
f5:a4:0b:5e:76:70:0a:47:a4:db:45:2e:15:99:69:f9:6b:14:
|
||||
93:2a:0a:b6:ee:53:a6:b9:02:9b:a2:25:37:1e:37:70:a2:7c:
|
||||
7f:c3:ce:98:17:2f:9b:5b:fa:6f:ae:d8:0e:d4:6a:b2:03:5a:
|
||||
fe:ba:4b:7f:f6:98:20:ea:cb:be:17:34:e0:43:74:d1:0c:e5:
|
||||
d4:cc:5d:13:41:d3:5e:a4:f6:94:f7:15:b8:15:a9:65:f8:28:
|
||||
3f:da:ef:b2:30:34:6d:96:3a:7a:f4:20:ec:9e:62:13:36:f1:
|
||||
a7:04:e1:7a:d2:33:20:f6:61:4a:68:44:cb:92:d7:62:f0:e4:
|
||||
70:f0:a5:e3:dd:2f:e2:a3
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFGTCCAwGgAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwWjELMAkGA1UEBhMCVVMx
|
||||
EzARBgNVBAgMCkNhbGlmb3JuaWExEjAQBgNVBAoMCU9wZW5SZXN0eTEiMCAGA1UE
|
||||
AwwZT3BlblJlc3R5IFRlc3RpbmcgUm9vdCBDQTAeFw0xOTA5MTMyMjMwNDlaFw0y
|
||||
OTA5MTAyMjMwNDlaMFAxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlh
|
||||
MRIwEAYDVQQKDAlPcGVuUmVzdHkxGDAWBgNVBAMMD2Zvb0BleGFtcGxlLmNvbTCC
|
||||
ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANCMHiwlfwCdij2K87UdayT1
|
||||
rDV9zbfQr9uIfO6CRhZH80MIoQRuDT7OafrViRSCIPFH8jjIq+ovHvAVBMD0izzD
|
||||
1HhWh0zxcKwRhi7Eam0QhCeByiqLhT5iE15AbBnkST3z3qroXhGh8maDakDRNMW/
|
||||
uMuXfGrqRr8XvjKNqDFW5YttCAPQRGm5rx4VHaVknhKEg9vZxnGQO8J7QSFXr3AV
|
||||
C1ZZIaZORnFmkPHvvLJI+Yvq5XJKukquLXQLMwP2LkcPVqQA6B5iy7ivnJgaiXzQ
|
||||
o3pa4YRQZORdpXCkaVTE9HZEor4b79yj2B0NMKLUefs5dqu3GPL3kviBg5S4EbEC
|
||||
AwEAAaOB8jCB7zAJBgNVHRMEAjAAMBEGCWCGSAGG+EIBAQQEAwIFoDAzBglghkgB
|
||||
hvhCAQ0EJhYkT3BlblNTTCBHZW5lcmF0ZWQgQ2xpZW50IENlcnRpZmljYXRlMB0G
|
||||
A1UdDgQWBBTS5PUhHBek/xP0Giiop9zG3omgMTAfBgNVHSMEGDAWgBS6ij56F2UM
|
||||
VxBT6Pmo40wqHQ20VDAOBgNVHQ8BAf8EBAMCBeAwHQYDVR0lBBYwFAYIKwYBBQUH
|
||||
AwIGCCsGAQUFBwMEMCsGA1UdEQQkMCKBD2Zvb0BleGFtcGxlLmNvbYEPYmFyQGV4
|
||||
YW1wbGUuY29tMA0GCSqGSIb3DQEBCwUAA4ICAQBHd1E3APco2sTZTjjE7OokyYM2
|
||||
TJCTp7IrEL913wty2OdPT2jlMi81iReVXLtD/HCJRghDYaxBYoQBlIjR3Iq9MCwY
|
||||
61F5C7cbtknfyYVV9nOft4OZUiP+5r0J2pC54ptoxN+9/iOUVTS+DX2EDFNpKg88
|
||||
R2g0Pyo/iT8+0ybOt1i80G/u+L1dxkiuoGwfbeBmk33bPAfmFa6q49A97wS23VMW
|
||||
k2Fw6a/A6R3/K+UKA1ZIPxzc/humbfZUq0HlO1ur9YEQRia76tcOM7FeME2BhmOa
|
||||
Sk8eRLnCxghO2vo6VdqWfAH21eg7uukxOxxRORpZ8ODHFy72GJ3sp0gwuExt5UpP
|
||||
Q0HLDmusrYdEkHaFIyvrj5dLIhNgIDo3pNx0fYU9ofUaA/bVeMe8mwnyyAUnQyqs
|
||||
UCE67oMt2wJvx5HeY9Y2fXqfH/tIYvT7jjrqYZs8A/n4pd8bAhQs3ubjR9JEZZQa
|
||||
xuH9uo22+JOpRkYmebC/V6iiIGZWfsn1pAtednAKR6TbRS4VmWn5axSTKgq27lOm
|
||||
uQKboiU3Hjdwonx/w86YFy+bW/pvrtgO1GqyA1r+ukt/9pgg6su+FzTgQ3TRDOXU
|
||||
zF0TQdNepPaU9xW4Fall+Cg/2u+yMDRtljp69CDsnmITNvGnBOF60jMg9mFKaETL
|
||||
ktdi8ORw8KXj3S/iow==
|
||||
-----END CERTIFICATE-----
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEowIBAAKCAQEA0IweLCV/AJ2KPYrztR1rJPWsNX3Nt9Cv24h87oJGFkfzQwih
|
||||
BG4NPs5p+tWJFIIg8UfyOMir6i8e8BUEwPSLPMPUeFaHTPFwrBGGLsRqbRCEJ4HK
|
||||
KouFPmITXkBsGeRJPfPequheEaHyZoNqQNE0xb+4y5d8aupGvxe+Mo2oMVbli20I
|
||||
A9BEabmvHhUdpWSeEoSD29nGcZA7wntBIVevcBULVlkhpk5GcWaQ8e+8skj5i+rl
|
||||
ckq6Sq4tdAszA/YuRw9WpADoHmLLuK+cmBqJfNCjelrhhFBk5F2lcKRpVMT0dkSi
|
||||
vhvv3KPYHQ0wotR5+zl2q7cY8veS+IGDlLgRsQIDAQABAoIBAEpoY++OZVT74LH6
|
||||
nN+XIn5qZUokm7yk6cnjVefndUhH3aSiNIkXFwS8sxV7ENDPaR+NcwANoUEKFPjG
|
||||
Fw8dcXx5xpo1DUtHrdLG4eBX1j0Zsn1CErbBVwYeChkL1UYbrII9O8ow5DdYV9t5
|
||||
sfR0cGbJ9A43+31OH3XY69SvtD39xItgxK0Wg4Ciz475kCvG51Q1iBWAkm4koXhz
|
||||
VCha4wghs81wJ28HRMFZAFf2C+72rk6EypMUX2dYirvW/+7zONirk298NDMAOSBh
|
||||
mRWyPV8qipYx42hBQ9vSVm0UVb0ZbqVomKKUZfj11LL6Ad/OzCyVAiNLXyZREV6r
|
||||
d324Bu0CgYEA/YPsE6p6H3MTPIoVTnsyyQw0pNmXtIAuYTgSveeuPoTYn3ZBWoGN
|
||||
iLpbnW4EH3xNKfrdMjbqqLls1iwm7/ZAP5klAuL4s10onrcjMt65fyfa3Lw1gavG
|
||||
SUFFdsueH2k3FohqNsbQUSXZILVQnXsRoldi38b7NKrAqABcEMAIqXMCgYEA0pde
|
||||
nt4aMmrGBRPLnjCs1UlC5PbXzCE8XxxQ7HZKx4Sy5ErQ0EW1wzF6c0fEYI7i+j1/
|
||||
ESKqekzc5ue0T8acoioB+VUybO1oxQZsZUPY7roqXOYwZH9LQOdPYUOh9k33CZHw
|
||||
6KFfx8bKCpdXn7FkwR2UUtCSp/6CZcyYr89Qn0sCgYAQ0L5I86bUDTL6cgJFyWAt
|
||||
+7RGNvScEWCCLFD57bMeDHu93/8nvK4hopLPF2wIlpsbrLsdSI06EcqJTjZq9j9+
|
||||
uG6/CUULyKMYG/emuSU+rOsUdxtpdXZah4zO+2SKmtT/lp7M8VUB/OuxArXNLEuY
|
||||
JAm35B/nd2f9/MAekE5CxwKBgQCV660w7G0590mB09XhiEWCkeVNm22FpSOVklMK
|
||||
BCy4XX/9hkWh//6mN1M1PqJPG2n7PEx5pnQ3HQEmYU28fWiFCeLd3glIArvTh/8j
|
||||
GGoXifEescFByl2IlyOr2roy3s4/weX/tuK5Fow/ff6jcWaJFMXDLzk437d1QXJx
|
||||
tuVugQKBgByfr2eakXFQvAVGJUfVXA3M2BoBODZEPYTgryVMoEEduFy0HZiw4xKi
|
||||
Dngwewy6/UJMAGA+8ak9Ca367FxnegZU9knm6ujYVyhU5WzbKpR8v7OaUP8d5icq
|
||||
rCZZtglG0c8XfVpJjR4FsKA/qrFvKZpu5NdEw3o5/LSrV4HjqZQ6
|
||||
-----END RSA PRIVATE KEY-----
|
||||
112
src/deps/src/lua-resty-http/t/cert/mtls_server.crt
vendored
112
src/deps/src/lua-resty-http/t/cert/mtls_server.crt
vendored
|
|
@ -1,112 +0,0 @@
|
|||
Certificate:
|
||||
Data:
|
||||
Version: 3 (0x2)
|
||||
Serial Number: 4097 (0x1001)
|
||||
Signature Algorithm: sha256WithRSAEncryption
|
||||
Issuer: C=US, ST=California, O=OpenResty, CN=OpenResty Testing Root CA
|
||||
Validity
|
||||
Not Before: Sep 13 22:32:03 2019 GMT
|
||||
Not After : Sep 10 22:32:03 2029 GMT
|
||||
Subject: C=US, ST=California, O=OpenResty, CN=example.com
|
||||
Subject Public Key Info:
|
||||
Public Key Algorithm: rsaEncryption
|
||||
RSA Public-Key: (2048 bit)
|
||||
Modulus:
|
||||
00:bb:69:2b:30:43:b0:b4:cc:84:3f:22:39:65:65:
|
||||
6a:bd:75:a4:2b:7d:f7:ec:e4:12:e8:d1:c4:ce:7e:
|
||||
4e:54:5c:22:cc:d2:18:7f:3b:9e:cb:70:d9:7d:79:
|
||||
8f:05:93:b6:9f:2f:d5:33:d7:98:a2:ed:c5:00:93:
|
||||
e4:ca:bc:cb:f0:e1:63:3e:07:6b:38:6f:4d:09:45:
|
||||
f1:a1:3b:a3:ca:c0:47:c1:a1:0a:f8:c9:bb:c7:da:
|
||||
26:9d:d3:0b:35:24:01:3e:16:14:2e:44:38:8c:c9:
|
||||
09:02:41:9e:b6:fb:0c:aa:fc:d6:44:5e:27:ab:aa:
|
||||
d5:c3:68:e1:dd:57:06:6c:4f:f6:24:33:a8:2b:49:
|
||||
60:82:0e:15:aa:55:9f:61:cc:74:39:7e:9f:a6:4f:
|
||||
71:4a:8b:eb:43:dd:c2:f7:90:38:df:a6:a6:a8:f6:
|
||||
77:bc:9e:54:69:30:83:4c:2a:eb:b8:62:7c:c7:14:
|
||||
84:9e:f3:e1:4a:15:33:51:65:a3:af:9d:09:c6:b8:
|
||||
89:30:a3:d2:18:e9:dc:5d:6b:ea:68:ca:8b:5c:e4:
|
||||
3b:fe:32:7f:48:c3:4c:f0:b5:06:f6:23:97:3e:f2:
|
||||
50:90:68:26:39:6d:b2:e2:53:89:71:6a:48:f0:f1:
|
||||
fc:89:3c:6d:db:87:6c:79:23:ed:87:5d:c5:fa:8a:
|
||||
0d:b9
|
||||
Exponent: 65537 (0x10001)
|
||||
X509v3 extensions:
|
||||
X509v3 Basic Constraints:
|
||||
CA:FALSE
|
||||
Netscape Cert Type:
|
||||
SSL Server
|
||||
Netscape Comment:
|
||||
OpenSSL Generated Server Certificate
|
||||
X509v3 Subject Key Identifier:
|
||||
8C:8E:18:2C:13:84:C9:2A:61:6B:73:3F:18:76:A4:85:55:5F:5C:5F
|
||||
X509v3 Authority Key Identifier:
|
||||
keyid:BA:8A:3E:7A:17:65:0C:57:10:53:E8:F9:A8:E3:4C:2A:1D:0D:B4:54
|
||||
DirName:/C=US/ST=California/O=OpenResty/CN=OpenResty Testing Root CA
|
||||
serial:7D:38:7C:F4:DC:B1:C6:66:D5:C0:D6:7F:60:57:5D:B2:C5:9C:F9:69
|
||||
|
||||
X509v3 Key Usage: critical
|
||||
Digital Signature, Key Encipherment
|
||||
X509v3 Extended Key Usage:
|
||||
TLS Web Server Authentication
|
||||
Signature Algorithm: sha256WithRSAEncryption
|
||||
80:9f:3e:f5:8b:50:ee:cb:e4:c2:f0:16:01:07:a1:af:76:bc:
|
||||
da:c8:cd:24:e9:63:df:d3:47:28:8c:7f:58:14:5d:d4:fd:44:
|
||||
16:c3:06:15:be:90:ec:1c:8f:78:34:11:e7:cc:86:d8:2a:a2:
|
||||
e5:99:70:83:76:4a:65:a4:e1:9a:68:20:29:c0:7a:c6:4a:08:
|
||||
b3:74:c3:53:b5:7b:79:92:f1:99:b5:a1:a3:90:ce:9a:cb:26:
|
||||
a5:a6:33:de:74:98:99:ec:18:d1:1e:41:be:f8:c3:d2:8d:aa:
|
||||
07:de:9a:97:28:0d:bf:70:ac:2b:cf:b7:ff:bc:ac:e4:16:0c:
|
||||
1c:03:a7:5a:2d:64:0d:90:16:bd:97:c3:1f:f5:bf:a9:fa:15:
|
||||
d1:e0:d4:0d:f7:b3:51:23:ce:ad:16:4f:41:72:17:aa:01:d5:
|
||||
44:e2:9e:d5:ce:ea:54:98:04:43:14:2e:51:4b:c7:d9:21:4f:
|
||||
e1:a4:fa:dd:e0:f0:82:ec:6f:9f:be:a2:3c:3b:85:f7:6d:96:
|
||||
ee:0d:e6:08:2b:1b:be:06:a4:b7:5f:a3:f2:f2:b9:d0:5a:8f:
|
||||
90:86:1a:f4:7a:9f:c8:ae:09:1d:60:a2:8b:e0:0b:f6:00:21:
|
||||
d9:df:33:4b:39:75:b6:64:9b:c7:df:e4:85:7a:ae:df:72:8c:
|
||||
8b:7e:98:8e:47:0a:27:1f:8e:2c:11:7f:7b:fc:a0:db:1b:6e:
|
||||
f6:de:4e:85:ac:30:e6:e8:6a:7a:e6:f9:f4:18:0a:c6:ad:1c:
|
||||
e1:0c:dd:e0:e0:8d:5a:d7:08:34:e7:22:b4:44:bd:99:39:b1:
|
||||
71:74:3f:7c:aa:65:f5:37:46:85:d3:79:f7:a8:35:8d:2b:30:
|
||||
99:d2:47:ce:a6:74:eb:f3:9f:d3:9a:4e:99:96:50:7b:ba:22:
|
||||
c8:72:47:d4:da:6e:9a:73:01:3c:89:e9:3f:56:17:b7:ba:22:
|
||||
71:db:66:a2:d2:fb:33:51:36:f6:b6:f2:5b:32:70:9d:e7:e3:
|
||||
36:d6:ae:cb:9b:62:ef:69:c7:f7:ba:95:49:16:f5:7c:d9:29:
|
||||
bb:0a:02:b1:6b:72:15:ab:2c:27:7b:c8:bc:f6:15:1f:fa:ae:
|
||||
08:fd:e0:11:36:b1:ab:9c:c8:11:d1:d3:0d:7d:49:4e:ca:e6:
|
||||
73:ee:0d:c3:8d:6f:f5:a4:fe:a1:af:6b:91:f7:53:fd:10:df:
|
||||
77:dd:ef:ec:7b:cf:32:75:df:04:8a:d1:a1:f7:36:68:ee:65:
|
||||
e3:43:90:37:43:e8:d1:a8:e2:90:5c:1c:75:0a:29:94:4a:6a:
|
||||
9b:89:28:43:bd:85:56:0d:f1:2b:44:bd:e6:7a:4c:b7:85:10:
|
||||
77:b7:a8:0f:33:29:a7:26
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFWTCCA0GgAwIBAgICEAEwDQYJKoZIhvcNAQELBQAwWjELMAkGA1UEBhMCVVMx
|
||||
EzARBgNVBAgMCkNhbGlmb3JuaWExEjAQBgNVBAoMCU9wZW5SZXN0eTEiMCAGA1UE
|
||||
AwwZT3BlblJlc3R5IFRlc3RpbmcgUm9vdCBDQTAeFw0xOTA5MTMyMjMyMDNaFw0y
|
||||
OTA5MTAyMjMyMDNaMEwxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlh
|
||||
MRIwEAYDVQQKDAlPcGVuUmVzdHkxFDASBgNVBAMMC2V4YW1wbGUuY29tMIIBIjAN
|
||||
BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu2krMEOwtMyEPyI5ZWVqvXWkK333
|
||||
7OQS6NHEzn5OVFwizNIYfzuey3DZfXmPBZO2ny/VM9eYou3FAJPkyrzL8OFjPgdr
|
||||
OG9NCUXxoTujysBHwaEK+Mm7x9omndMLNSQBPhYULkQ4jMkJAkGetvsMqvzWRF4n
|
||||
q6rVw2jh3VcGbE/2JDOoK0lggg4VqlWfYcx0OX6fpk9xSovrQ93C95A436amqPZ3
|
||||
vJ5UaTCDTCrruGJ8xxSEnvPhShUzUWWjr50JxriJMKPSGOncXWvqaMqLXOQ7/jJ/
|
||||
SMNM8LUG9iOXPvJQkGgmOW2y4lOJcWpI8PH8iTxt24dseSPth13F+ooNuQIDAQAB
|
||||
o4IBNTCCATEwCQYDVR0TBAIwADARBglghkgBhvhCAQEEBAMCBkAwMwYJYIZIAYb4
|
||||
QgENBCYWJE9wZW5TU0wgR2VuZXJhdGVkIFNlcnZlciBDZXJ0aWZpY2F0ZTAdBgNV
|
||||
HQ4EFgQUjI4YLBOEySpha3M/GHakhVVfXF8wgZcGA1UdIwSBjzCBjIAUuoo+ehdl
|
||||
DFcQU+j5qONMKh0NtFShXqRcMFoxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxp
|
||||
Zm9ybmlhMRIwEAYDVQQKDAlPcGVuUmVzdHkxIjAgBgNVBAMMGU9wZW5SZXN0eSBU
|
||||
ZXN0aW5nIFJvb3QgQ0GCFH04fPTcscZm1cDWf2BXXbLFnPlpMA4GA1UdDwEB/wQE
|
||||
AwIFoDATBgNVHSUEDDAKBggrBgEFBQcDATANBgkqhkiG9w0BAQsFAAOCAgEAgJ8+
|
||||
9YtQ7svkwvAWAQehr3a82sjNJOlj39NHKIx/WBRd1P1EFsMGFb6Q7ByPeDQR58yG
|
||||
2Cqi5Zlwg3ZKZaThmmggKcB6xkoIs3TDU7V7eZLxmbWho5DOmssmpaYz3nSYmewY
|
||||
0R5BvvjD0o2qB96alygNv3CsK8+3/7ys5BYMHAOnWi1kDZAWvZfDH/W/qfoV0eDU
|
||||
DfezUSPOrRZPQXIXqgHVROKe1c7qVJgEQxQuUUvH2SFP4aT63eDwguxvn76iPDuF
|
||||
922W7g3mCCsbvgakt1+j8vK50FqPkIYa9HqfyK4JHWCii+AL9gAh2d8zSzl1tmSb
|
||||
x9/khXqu33KMi36YjkcKJx+OLBF/e/yg2xtu9t5Ohaww5uhqeub59BgKxq0c4Qzd
|
||||
4OCNWtcINOcitES9mTmxcXQ/fKpl9TdGhdN596g1jSswmdJHzqZ06/Of05pOmZZQ
|
||||
e7oiyHJH1NpumnMBPInpP1YXt7oicdtmotL7M1E29rbyWzJwnefjNtauy5ti72nH
|
||||
97qVSRb1fNkpuwoCsWtyFassJ3vIvPYVH/quCP3gETaxq5zIEdHTDX1JTsrmc+4N
|
||||
w41v9aT+oa9rkfdT/RDfd93v7HvPMnXfBIrRofc2aO5l40OQN0Po0ajikFwcdQop
|
||||
lEpqm4koQ72FVg3xK0S95npMt4UQd7eoDzMppyY=
|
||||
-----END CERTIFICATE-----
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEowIBAAKCAQEAu2krMEOwtMyEPyI5ZWVqvXWkK3337OQS6NHEzn5OVFwizNIY
|
||||
fzuey3DZfXmPBZO2ny/VM9eYou3FAJPkyrzL8OFjPgdrOG9NCUXxoTujysBHwaEK
|
||||
+Mm7x9omndMLNSQBPhYULkQ4jMkJAkGetvsMqvzWRF4nq6rVw2jh3VcGbE/2JDOo
|
||||
K0lggg4VqlWfYcx0OX6fpk9xSovrQ93C95A436amqPZ3vJ5UaTCDTCrruGJ8xxSE
|
||||
nvPhShUzUWWjr50JxriJMKPSGOncXWvqaMqLXOQ7/jJ/SMNM8LUG9iOXPvJQkGgm
|
||||
OW2y4lOJcWpI8PH8iTxt24dseSPth13F+ooNuQIDAQABAoIBABnT/KfCLHA+X1t0
|
||||
FATtXTCPLfjwe2KibBi6EC2FKrZlnEYuDkI6rT/MZaztO9DA8sItjWx/ogGSUzwp
|
||||
JbbrHhAsf8jkrNoyPKOyiAJ4fbJLnZgJ4cE3zDFW10uY8kp4k9NCp7VYoZKFgkBV
|
||||
WtJM9wn5nm39q+n0uVEc+0PN4oy6m54Aqb1HqVCyXFp+/pVhL6PtgaClbqJd3oKV
|
||||
0/HLWfWaI3nvV6ltAphUfPoCmYIUtSl90sRgSeEaJ61UZXh0OkhhtD7Iw/JUlHDk
|
||||
a0J7owrh0Wf1kDsaSn+j1ba8MELsspFYYVm0gAMKAvRXbVrYgUMdb+HVdZ0odULl
|
||||
ezFWeAECgYEA9nnoZs+PzKWNxTzYPtgvvrSLmpXLzNrs/p41JUhy6GjQIixTSBFy
|
||||
WHkjwu0k2fvRgODfcaetAyK6sV4uTpRgqUhtFSeyNMelZ2yiIEqvhUrtHoVov1C+
|
||||
BqwwlUnmkQZNQODXOpKCvnqnOaPwMILKLtxDGmPtW0tCTR2dVVaht6ECgYEAwqb/
|
||||
h0Fh3YtykOnhV8wOZRrpVr8jS1RIgg/hklt2xh6+OYtL16sKFaLBF/BhzZRBapqd
|
||||
fB2Cx3B6rxZ5PLTse8yjEvjt6Ly7TusYWpaKbYKFnnEbmdsm5sBepuLUv4AoMYbk
|
||||
99ZejFcQI2gNbzX7eIrFitCQGxT+Wu7Gncv+vxkCgYBvAYCVrS2KcZVkG38Y7qyy
|
||||
KwYk3QoofQD3u7Eb1YFLAsmaWnQ3pQPmrMhaZguO0UcN0DlSKr5VBzMl5tDcOx89
|
||||
noziVjqAYtovtlFeUcSzN4eLk3IVl/u9bZeD5QCemEP60Eie7JVNzFe8MgVfE8iT
|
||||
Skg+fnrL/x0hNhFB+f5jgQKBgDgOEX4o5P8A3nA++gbnm6mgE1xI1OgnkG3sFuCn
|
||||
+E9boRo/NAsalV/fq82yCuhB7oi9l+abNQMsMBhl12oVDBkmuDuJdjHUz/gNGclU
|
||||
mu6obMRQ/ErVYqGG+nsCzZOMW4bPuvZoRHgTxnD70QqauB1hkTvFjgpOhGU5Z/cf
|
||||
PPBZAoGBAJQK7NF6VoF9nm5CT8vufrQ2vvp2aiLdOLLx5JXt/6seEnPZWtEvjp8/
|
||||
+ExIsfOIaU5elhv8ze8iKmRP9f04XdWpbRm6k6AR5cOkkQQ1oO7N9abU7KbD/gqX
|
||||
pJIWOlaUrbKO4Dprx7HyMYYPs9mu/UoF0Dvd/+bYXM5ZKiFrQ3Ly
|
||||
-----END RSA PRIVATE KEY-----
|
||||
21
src/deps/src/lua-resty-http/t/cert/test.crt
vendored
21
src/deps/src/lua-resty-http/t/cert/test.crt
vendored
|
|
@ -1,21 +0,0 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIDYzCCAkugAwIBAgIUXCmnoPKJ60jFkycVZ04mVj3B8aswDQYJKoZIhvcNAQEL
|
||||
BQAwQTELMAkGA1UEBhMCUFQxDjAMBgNVBAgMBVBvcnRvMQ4wDAYDVQQHDAVQb3J0
|
||||
bzESMBAGA1UECgwJbGVkZ2V0ZWNoMB4XDTIyMTIxNTEyMDQzMVoXDTMyMDkxMzEy
|
||||
MDQzMVowQTELMAkGA1UEBhMCUFQxDjAMBgNVBAgMBVBvcnRvMQ4wDAYDVQQHDAVQ
|
||||
b3J0bzESMBAGA1UECgwJbGVkZ2V0ZWNoMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A
|
||||
MIIBCgKCAQEAqzJINgQtchR799ahPpu2gweHCmx7cytQ59ZFW4J3QBRIB+DFnLSM
|
||||
fJa797s0Sl6f+t9pT3QLYjbdNK+R60HGd5tM31cEIa518AcDokfkzGo/clY+dbs4
|
||||
OcFe10HxAlXpu6S5/yiQ0u4CIf1uQSsS53kNpaRWcEz6Z/sw80ksCEnYSfD3YXEh
|
||||
sJm41i5Hd4F2/Y1WrMg82YGZG7Y81cM9LgUxKcikTm4JnEn9G1yg56hSbKs1a0E0
|
||||
J9Gk84lufWpiUqpX9ASsUPttnYzgljo24x7zeNEaXsVOKgu+88Cc+bBn7AORGXM4
|
||||
YtYbxVGhAgPf0vOalNl/kDwfE1jwBz0r6QIDAQABo1MwUTAdBgNVHQ4EFgQUxuo7
|
||||
FdlD/iQ7cMnORpKFQ0JW9I4wHwYDVR0jBBgwFoAUxuo7FdlD/iQ7cMnORpKFQ0JW
|
||||
9I4wDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAfINyfrlE/f3W
|
||||
cTNFiVMzqCa+oeNtvlkaCKgtjJdow8xwAc/Mxae76dkN3Mh8yegKV9+QRY6rw6q0
|
||||
dfma/Rg0tJgrI9El64XdGRcMpwGdtujZbE/bCGTJwLpcIM051cr/NCtYYduM2RU8
|
||||
i5uc8z5sQbMIJHdwDDm4PevA4WrqteUo5bXFQp9jYessDIkjIg7n5hGNvSNtfpVV
|
||||
0fGDYPD9yNydgRMe6EwqQ0Z9p6yfq4o60JceYt4MfbbcGxzwrQc41ou2wKM/iKnQ
|
||||
FBwCOaa+imgn01Qno/PdisV05KM7uSv/dK1v33nrk4xPSVG8u0aGe440U1CcGXbB
|
||||
jy3ACMw/ZQ==
|
||||
-----END CERTIFICATE-----
|
||||
28
src/deps/src/lua-resty-http/t/cert/test.key
vendored
28
src/deps/src/lua-resty-http/t/cert/test.key
vendored
|
|
@ -1,28 +0,0 @@
|
|||
-----BEGIN PRIVATE KEY-----
|
||||
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCrMkg2BC1yFHv3
|
||||
1qE+m7aDB4cKbHtzK1Dn1kVbgndAFEgH4MWctIx8lrv3uzRKXp/632lPdAtiNt00
|
||||
r5HrQcZ3m0zfVwQhrnXwBwOiR+TMaj9yVj51uzg5wV7XQfECVem7pLn/KJDS7gIh
|
||||
/W5BKxLneQ2lpFZwTPpn+zDzSSwISdhJ8PdhcSGwmbjWLkd3gXb9jVasyDzZgZkb
|
||||
tjzVwz0uBTEpyKRObgmcSf0bXKDnqFJsqzVrQTQn0aTziW59amJSqlf0BKxQ+22d
|
||||
jOCWOjbjHvN40RpexU4qC77zwJz5sGfsA5EZczhi1hvFUaECA9/S85qU2X+QPB8T
|
||||
WPAHPSvpAgMBAAECggEADrAtoUwCQpRYWIv9LkJ5sJjmPX8DDn9Fnaz099d9qy1L
|
||||
5GuLRbLF9PCRdKO55k5jenvnOXs5RZym2QNEfHaA9GuKKmvF8N/awmFpSE46M4Gp
|
||||
xOhHMdG1qFroOLhkv1cNfhB+XTjzrm1GS8VGZU5jr+5Jo4/lUxUZTO+XCq1mAXK0
|
||||
io58x7K3Z7P26/46yeuuqNggbFCxeHfHSK8SXYg6QxgjlZyA/A8tHDuvhDCH81q/
|
||||
AISHxIFmly8ZQ2KxuVCSyHXQkPwODPh2F/4UpOq5EdN781CuV/W4e73WKBwcDUQM
|
||||
aEX5KF8D2C0nXjk592SS9SFmXqw9ZD77sAL2JmbE4wKBgQDGoKT8i3xn3x4nAju0
|
||||
yTxK6jaV72Lrdn5HmOZyJb8irAUr9B0t33zaubzXlM1LpuS/JAQwtppShGo1jPlt
|
||||
T8iE2+JR9UKi6siHV/3EKC15i5UT3p30txdR2KS+hAasb7qXvM6sgM0nwzoS9PUy
|
||||
LbKnRN8UYTvJmEKU1vuyeFQAQwKBgQDcpUQpNhtf4GrT7EoBh8E24yOO2k9XludW
|
||||
yhaEddTYe2FXmqf9MGuPPX+dBj3G1SY6RNXvjmVjr3uvFN5qz+mtOuAkm7g99KkI
|
||||
bKjkVuCgx6mpiH89dt7d/3uTcKXEkai0F7JgSPd1mcSxjRybhyna4qC4CuCHjICU
|
||||
Ug00LAqGYwKBgGjX6N6JPgySABd1HVDrG9ErWc7AwkUpkbR3J8S+2eoSRNSTkUdi
|
||||
fUPy4JQmrkqteHbQKwoPiNvfmzRTCmHByEUgz5CVViwqo9iVAJUm5AIRRIptapD+
|
||||
h+ei5CrQA7nHbAWmGq2Be0juytuwwzBOYMvcFahrPqTFovdvlwH4c9aDAoGAYAk6
|
||||
4qkfPxrhxH3rNEFPUsGIX4wbzqbq6DarmFnlG5iQJN420hf6KO1+luz5hIqPyfre
|
||||
Fxemf74Imor9yAXY0sJ2fticV7Mew4Dv/frmaHSfHyA/KZSMqpmhwunb7PPtNv29
|
||||
cPUxaClWmGUwF228RP4xMAnj8nuwF16jSpsEtbsCgYEAxEaEzpuknqV4AOnlJFBQ
|
||||
7JqSkvW7w4Zy8hnUNmqhOOX1KwB0YudfirHceGtOpjxWQmHqjCHZqau0nEU02+ev
|
||||
qUQsdiGKeJvWHYyqEldOdNd49qaux19IPQBeKRJQGWheGHDWGlg1aSDw3jY0sESS
|
||||
3VqdbL5Z3XRXozQdwmNyfbw=
|
||||
-----END PRIVATE KEY-----
|
||||
Loading…
Reference in a new issue