Skip to content

Commit b683108

Browse files
committed
http/request: make sure we start tls when using a https proxy
1 parent a4acf73 commit b683108

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

http/request.lua

+1
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ function request_methods:go(timeout)
458458
end
459459
host = assert(proxy.host, "proxy is missing host")
460460
port = proxy.port or http_util.scheme_to_port[proxy.scheme]
461+
tls = (proxy.scheme == "https")
461462
-- TODO: figure out what :path should be when using a http2 proxy
462463
if version ~= 2 then
463464
-- for now, just force 1.1

spec/request_spec.lua

+25
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,31 @@ describe("http.request module", function()
630630
stream:shutdown()
631631
end)
632632
end)
633+
it("works with a tls proxy server", function()
634+
test(function(stream)
635+
local h = assert(stream:get_headers())
636+
assert.truthy(stream:checktls()) -- came in via TLS
637+
local _, host, port = stream:localname()
638+
local authority = http_util.to_authority(host, port, "http")
639+
assert.same("http", h:get(":scheme"))
640+
assert.same(authority, h:get ":authority")
641+
assert.same("/", h:get(":path"))
642+
local resp_headers = new_headers()
643+
resp_headers:append(":status", "200")
644+
assert(stream:write_headers(resp_headers, false))
645+
assert(stream:write_chunk("hello world", true))
646+
end, function(req)
647+
req.proxy = {
648+
scheme = "https";
649+
host = req.host;
650+
port = req.port;
651+
}
652+
local headers, stream = assert(req:go())
653+
assert.same("200", headers:get(":status"))
654+
assert.same("hello world", assert(stream:get_body_as_string()))
655+
stream:shutdown()
656+
end)
657+
end)
633658
it("works with a proxy server with a path component", function()
634659
test(function(stream)
635660
local h = assert(stream:get_headers())

0 commit comments

Comments
 (0)