Skip to content

Commit 072db57

Browse files
committed
spec/request_spec.lua: Add tests for non-empty path for proxy
1 parent dd8e4df commit 072db57

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

spec/request_spec.lua

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,30 @@ describe("http.request module", function()
629629
stream:shutdown()
630630
end)
631631
end)
632+
it("works with a proxy server with a path component", function()
633+
test(function(stream)
634+
local h = assert(stream:get_headers())
635+
local _, host, port = stream:localname()
636+
local authority = http_util.to_authority(host, port, "http")
637+
assert.same(authority, h:get ":authority")
638+
assert.same("http://" .. authority .. "/", h:get(":path"))
639+
local resp_headers = new_headers()
640+
resp_headers:append(":status", "200")
641+
assert(stream:write_headers(resp_headers, false))
642+
assert(stream:write_chunk("hello world", true))
643+
end, function(req)
644+
req.proxy = {
645+
scheme = "http";
646+
host = req.host;
647+
port = req.port;
648+
path = "/path";
649+
}
650+
local headers, stream = assert(req:go())
651+
assert.same("200", headers:get(":status"))
652+
assert.same("hello world", assert(stream:get_body_as_string()))
653+
stream:shutdown()
654+
end)
655+
end)
632656
it("works with http proxies on OPTIONS requests", function()
633657
test(function(stream)
634658
local h = assert(stream:get_headers())
@@ -716,6 +740,34 @@ describe("http.request module", function()
716740
stream:shutdown()
717741
end)
718742
end)
743+
it("CONNECT proxy with path component", function()
744+
test(function(stream, s)
745+
local h = assert(stream:get_headers())
746+
local resp_headers = new_headers()
747+
resp_headers:append(":status", "200")
748+
assert(stream:write_headers(resp_headers, false))
749+
if h:get(":method") == "CONNECT" then
750+
assert(stream.connection.version < 2)
751+
local sock = assert(stream.connection:take_socket())
752+
s:add_socket(sock)
753+
return true
754+
else
755+
assert(stream:write_chunk("hello world", true))
756+
end
757+
end, function(req)
758+
req.tls = true
759+
req.proxy = {
760+
scheme = "http";
761+
host = req.host;
762+
port = req.port;
763+
path = "/path";
764+
}
765+
local headers, stream = assert(req:go())
766+
assert.same("200", headers:get(":status"))
767+
assert.same("hello world", assert(stream:get_body_as_string()))
768+
stream:shutdown()
769+
end)
770+
end)
719771
it("fails correctly on non CONNECT proxy", function()
720772
test(function(stream)
721773
local h = assert(stream:get_headers())

0 commit comments

Comments
 (0)