Skip to content

Commit

Permalink
Fix normalization of URI in request.
Browse files Browse the repository at this point in the history
Resolves #246. Again.
  • Loading branch information
ixti committed Aug 19, 2015
1 parent 5e5c029 commit 8c8486c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion lib/http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class UnsupportedSchemeError < RequestError; end
# :nodoc:
def initialize(verb, uri, headers = {}, proxy = {}, body = nil, version = "1.1") # rubocop:disable ParameterLists
@verb = verb.to_s.downcase.to_sym
@uri = HTTP::URI.parse(uri).normalize
@uri = normalize_uri uri
@scheme = @uri.scheme && @uri.scheme.to_s.downcase.to_sym

fail(UnsupportedMethodError, "unknown method: #{verb}") unless METHODS.include?(@verb)
Expand Down Expand Up @@ -172,5 +172,18 @@ def port
def default_host_header_value
PORTS[@scheme] != port ? "#{host}:#{port}" : host
end

# @return [HTTP::URI] URI with all componentes but query being normalized.
def normalize_uri(uri)
uri = HTTP::URI.parse uri

HTTP::URI.new(
:scheme => uri.normalized_scheme,
:authority => uri.normalized_authority,
:path => uri.normalized_path,
:query => uri.query,
:fragment => uri.normalized_fragment
)
end
end
end
4 changes: 2 additions & 2 deletions lib/http/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

module HTTP
class URI < Addressable::URI
# HTTP scheme
# @private
HTTP_SCHEME = "http".freeze

# HTTPS scheme
# @private
HTTPS_SCHEME = "https".freeze

# @return [True] if URI is HTTP
Expand Down

0 comments on commit 8c8486c

Please sign in to comment.