diff --git a/lib/http/client.rb b/lib/http/client.rb index 7a6e9148..dacc7500 100644 --- a/lib/http/client.rb +++ b/lib/http/client.rb @@ -107,8 +107,8 @@ def close # Verify our request isn't going to be made against another URI def verify_connection!(uri) - if default_options.persistent? && base_host(uri) != default_options.persistent - fail StateError, "Persistence is enabled for #{default_options.persistent}, but we got #{base_host(uri)}" + if default_options.persistent? && uri.origin != default_options.persistent + fail StateError, "Persistence is enabled for #{default_options.persistent}, but we got #{uri.origin}" # We re-create the connection object because we want to let prior requests # lazily load the body as long as possible, and this mimics prior functionality. elsif @connection && (!@connection.keep_alive? || @connection.expired?) @@ -120,11 +120,6 @@ def verify_connection!(uri) end end - # Strips out query/path to give us a consistent way of comparing hosts - def base_host(uri) - uri.omit(:query, :path).to_s - end - # Merges query params if needed # # @param [#to_s] uri diff --git a/lib/http/options.rb b/lib/http/options.rb index 2fbf4eb8..145074a7 100644 --- a/lib/http/options.rb +++ b/lib/http/options.rb @@ -2,6 +2,7 @@ require "openssl" require "socket" require "http/cache/null_cache" +require "http/uri" module HTTP class Options @@ -81,6 +82,14 @@ def follow=(value) end end + def persistent=(value) + @persistent = value ? HTTP::URI.parse(value).origin : nil + end + + def persistent? + !persistent.nil? + end + def_option :cache do |cache_or_cache_options| if cache_or_cache_options.respond_to? :perform cache_or_cache_options @@ -90,10 +99,6 @@ def follow=(value) end end - def persistent? - !persistent.nil? && persistent != "" - end - def [](option) send(option) rescue nil end