Skip to content

Commit

Permalink
http/request: make sure we start tls when using a https proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
daurnimator committed Mar 13, 2019
1 parent bf5c5ea commit 1f15d3f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions http/request.lua
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ function request_methods:go(timeout)
end
host = assert(proxy.host, "proxy is missing host")
port = proxy.port or http_util.scheme_to_port[proxy.scheme]
tls = (proxy.scheme == "https")
use_absolute_target = true
if proxy.userinfo then
if not cloned_headers then
Expand Down
25 changes: 25 additions & 0 deletions spec/request_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,31 @@ describe("http.request module", function()
stream:shutdown()
end)
end)
it("works with a tls proxy server", function()
test(function(stream)
local h = assert(stream:get_headers())
assert.truthy(stream:checktls()) -- came in via TLS
local _, host, port = stream:localname()
local authority = http_util.to_authority(host, port, "http")
assert.same("http", h:get(":scheme"))
assert.same(authority, h:get ":authority")
assert.same("/", h:get(":path"))
local resp_headers = new_headers()
resp_headers:append(":status", "200")
assert(stream:write_headers(resp_headers, false))
assert(stream:write_chunk("hello world", true))
end, function(req)
req.proxy = {
scheme = "https";
host = req.host;
port = req.port;
}
local headers, stream = assert(req:go())
assert.same("200", headers:get(":status"))
assert.same("hello world", assert(stream:get_body_as_string()))
stream:shutdown()
end)
end)
it("works with a proxy server with a path component", function()
test(function(stream)
local h = assert(stream:get_headers())
Expand Down

0 comments on commit 1f15d3f

Please sign in to comment.