Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'httparty'
require 'net/http/persistent'
module HTTParty
module ClassMethods
def persistent(value = true)
if value
default_options[:persistent] ||= Net::HTTP::Persistent.new 'httparty'
else
default_options[:persistent] = nil
end
end
end
class Request
alias non_persistent_http http
def http
if options[:persistent].nil?
non_persistent_http
else
options[:persistent]
end
end
alias non_persistent_perform_actual_request perform_actual_request
def perform_actual_request
if options[:persistent].nil?
non_persistent_perform_actual_request
else
http.request(uri, @raw_request)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.