diff --git a/http/request.lua b/http/request.lua index 85bbf237..25428542 100644 --- a/http/request.lua +++ b/http/request.lua @@ -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 diff --git a/spec/request_spec.lua b/spec/request_spec.lua index dffff0de..20e98b7a 100644 --- a/spec/request_spec.lua +++ b/spec/request_spec.lua @@ -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())