Skip to content

Commit d0b56ee

Browse files
committed
http/request: Only use absolute form in http < 2
1 parent 8c83eca commit d0b56ee

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
@@ -451,17 +451,29 @@ function request_methods:go(timeout)
451451
if request_headers:get(":method") == "CONNECT" then
452452
error("cannot use HTTP Proxy with CONNECT method")
453453
end
454-
-- TODO: Check if :path already has authority?
455-
local old_url = self:to_uri(false)
456454
host = assert(proxy.host, "proxy is missing host")
457455
port = proxy.port or http_util.scheme_to_port[proxy.scheme]
458-
-- proxy requests get a uri that includes host as their path
459-
if not cloned_headers then
460-
request_headers = request_headers:clone()
461-
cloned_headers = true -- luacheck: ignore 311
456+
-- TODO: figure out what :path should be when using a http2 proxy
457+
if version ~= 2 then
458+
-- for now, just force 1.1
459+
version = 1.1
460+
-- RFC 7230 Section 5.3.2
461+
-- When making a request to a proxy, other than a CONNECT or server-wide
462+
-- OPTIONS request (as detailed below), a client MUST send the target
463+
-- URI in absolute-form as the request-target.
464+
-- TODO: Check if :path already has authority?
465+
local old_url = self:to_uri(false)
466+
if not cloned_headers then
467+
request_headers = request_headers:clone()
468+
cloned_headers = true
469+
end
470+
request_headers:upsert(":path", old_url)
462471
end
463-
request_headers:upsert(":path", old_url)
464472
if proxy.userinfo then
473+
if not cloned_headers then
474+
request_headers = request_headers:clone()
475+
cloned_headers = true -- luacheck: ignore 311
476+
end
465477
request_headers:upsert("proxy-authorization", "basic " .. basexx.to_base64(proxy.userinfo), true)
466478
end
467479
end

0 commit comments

Comments
 (0)