diff --git a/lib/http/request.rb b/lib/http/request.rb index 1e03a870..4cb7cea3 100644 --- a/lib/http/request.rb +++ b/lib/http/request.rb @@ -114,13 +114,7 @@ def include_proxy_authorization_header # Compute HTTP request header for direct or proxy request def request_header - if using_proxy? - "#{verb.to_s.upcase} #{uri} HTTP/#{version}" - else - path = uri.query && !uri.query.empty? ? "#{uri.path}?#{uri.query}" : uri.path - path = '/' if path.empty? - "#{verb.to_s.upcase} #{path} HTTP/#{version}" - end + "#{verb.to_s.upcase} #{path_for_request_header} HTTP/#{version}" end # Host for tcp socket @@ -135,6 +129,23 @@ def socket_port private + def path_for_request_header + if using_proxy? + uri + else + uri_path_with_query + end + end + + def uri_path_with_query + path = uri_has_query? ? "#{uri.path}?#{uri.query}" : uri.path + path.empty? ? '/' : path + end + + def uri_has_query? + uri.query && !uri.query.empty? + end + # Default host (with port if needed) header value. # # @return [String]