lib/http/client.rb in http-0.8.14 vs lib/http/client.rb in http-0.9.0.pre
- old
+ new
@@ -1,7 +1,10 @@
require "forwardable"
+require "cgi"
+require "uri"
+
require "http/form_data"
require "http/options"
require "http/headers"
require "http/connection"
require "http/redirector"
@@ -40,23 +43,17 @@
Redirector.new(opts.follow).perform req, res do |request|
perform request, opts
end
end
- # Perform a single (no follow) HTTP request
- def perform(req, options)
- options.cache.perform(req, options) do |r, opts|
- make_request(r, opts)
- end
- end
-
# @!method persistent?
# @see Options#persistent?
# @return [Boolean] whenever client is persistent
def_delegator :default_options, :persistent?
- def make_request(req, options)
+ # Perform a single (no follow) HTTP request
+ def perform(req, options)
verify_connection!(req.uri)
@state = :dirty
@connection ||= HTTP::Connection.new(req, options)
@@ -110,20 +107,21 @@
# Merges query params if needed
#
# @param [#to_s] uri
# @return [URI]
- def make_request_uri(uri, opts)
+ def make_request_uri(uri, options)
uri = uri.to_s
if default_options.persistent? && uri !~ HTTP_OR_HTTPS_RE
uri = "#{default_options.persistent}#{uri}"
end
uri = HTTP::URI.parse uri
- if opts.params && !opts.params.empty?
- uri.query = [uri.query, HTTP::URI.form_encode(opts.params)].compact.join("&")
+ if options.params && !options.params.empty?
+ params = CGI.parse(uri.query.to_s).merge(options.params || {})
+ uri.query = ::URI.encode_www_form params
end
# Some proxies (seen on WEBRick) fail if URL has
# empty path (e.g. `http://example.com`) while it's RFC-complaint:
# http://tools.ietf.org/html/rfc1738#section-3.1