@@ -77,6 +77,7 @@ local function new_stream(connection)
7777
7878 req_method = nil ; -- string
7979 peer_version = nil ; -- 1.0 or 1.1
80+ use_absolute_target = nil ; -- tristate boolean
8081 has_main_headers = false ;
8182 headers_in_progress = nil ;
8283 headers_fifo = new_fifo ();
@@ -648,8 +649,32 @@ function stream_methods:write_headers(headers, end_stream, timeout)
648649 assert (not headers :has (" :path" ), " CONNECT requests should not have a path" )
649650 else
650651 -- RFC 7230 Section 5.4: A client MUST send a Host header field in all HTTP/1.1 request messages.
651- assert (self .connection .version < 1.1 or headers :has (" :authority" ), " missing authority" )
652+ local has_authority = headers :has (" :authority" )
653+ assert (has_authority or self .connection .version < 1.1 , " missing authority" )
652654 target = assert (headers :get (" :path" ), " missing path" )
655+
656+ local use_absolute_target = self .use_absolute_target
657+ if use_absolute_target then
658+ assert (has_authority , " request-target absolute-form requires an authority" )
659+ elseif use_absolute_target == nil then
660+ use_absolute_target = has_authority
661+ end
662+ if use_absolute_target then
663+ -- RFC 7230 Section 5.3.2
664+ -- When making a request to a proxy, other than a CONNECT or server-wide
665+ -- OPTIONS request (as detailed below), a client MUST send the target
666+ -- URI in absolute-form as the request-target.
667+ -- ...
668+ -- To allow for transition to the absolute-form for all requests in some
669+ -- future version of HTTP, a server MUST accept the absolute-form in
670+ -- requests, even though HTTP/1.1 clients will only send them in
671+ -- requests to proxies.
672+ if target == " *" then
673+ target = headers :get (" :scheme" ) .. " ://" .. headers :get (" :authority" )
674+ else
675+ target = headers :get (" :scheme" ) .. " ://" .. headers :get (" :authority" ) .. target
676+ end
677+ end
653678 end
654679 if self .connection .req_locked then
655680 -- Wait until previous request has been fully written
0 commit comments