lib/http/client.rb in http-0.8.0.pre vs lib/http/client.rb in http-0.8.0.pre2
- old
+ new
@@ -73,28 +73,30 @@
res
# On any exception we reset the conn. This is a safety measure, to ensure
# we don't have conns in a bad state resulting in mixed requests/responses
rescue
- if default_options.persistent? && @connection
- @connection.close
- @connection = nil
- end
+ close if default_options.persistent?
raise
end
+ def close
+ @connection.close if @connection
+ @connection = nil
+ end
+
private
# 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)}"
# 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 !default_options.persistent? || (@connection && !@connection.keep_alive?)
- @connection = nil
+ close
end
end
# Strips out query/path to give us a consistent way of comparing hosts
def base_host(uri)