Skip to content

Commit

Permalink
Merge pull request #156 from samphippen/samphippen/refactoring/reques…
Browse files Browse the repository at this point in the history
…t_header

Break up the Request#request_header a little
  • Loading branch information
ixti committed Aug 25, 2014
2 parents 403bbf3 + fe75f84 commit 2300318
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions lib/http/request.rb
Expand Up @@ -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
Expand All @@ -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]
Expand Down

0 comments on commit 2300318

Please sign in to comment.