Skip to content

Commit a4acf73

Browse files
committed
http/request: only use absolute form in http < 2
1 parent 1707e6f commit a4acf73

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

http/request.lua

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -456,17 +456,29 @@ function request_methods:go(timeout)
456456
if request_headers:get(":method") == "CONNECT" then
457457
error("cannot use HTTP Proxy with CONNECT method")
458458
end
459-
-- TODO: Check if :path already has authority?
460-
local old_url = self:to_uri(false)
461459
host = assert(proxy.host, "proxy is missing host")
462460
port = proxy.port or http_util.scheme_to_port[proxy.scheme]
463-
-- proxy requests get a uri that includes host as their path
464-
if not cloned_headers then
465-
request_headers = request_headers:clone()
466-
cloned_headers = true -- luacheck: ignore 311
461+
-- TODO: figure out what :path should be when using a http2 proxy
462+
if version ~= 2 then
463+
-- for now, just force 1.1
464+
version = 1.1
465+
-- RFC 7230 Section 5.3.2
466+
-- When making a request to a proxy, other than a CONNECT or server-wide
467+
-- OPTIONS request (as detailed below), a client MUST send the target
468+
-- URI in absolute-form as the request-target.
469+
-- TODO: Check if :path already has authority?
470+
local old_url = self:to_uri(false)
471+
if not cloned_headers then
472+
request_headers = request_headers:clone()
473+
cloned_headers = true
474+
end
475+
request_headers:upsert(":path", old_url)
467476
end
468-
request_headers:upsert(":path", old_url)
469477
if proxy.userinfo then
478+
if not cloned_headers then
479+
request_headers = request_headers:clone()
480+
cloned_headers = true -- luacheck: ignore 311
481+
end
470482
request_headers:upsert("proxy-authorization", "basic " .. basexx.to_base64(proxy.userinfo), true)
471483
end
472484
end

0 commit comments

Comments
 (0)