Skip to content

Instantly share code, notes, and snippets.

@phiggins
Created May 26, 2010 22:32
Show Gist options
  • Save phiggins/415173 to your computer and use it in GitHub Desktop.
Save phiggins/415173 to your computer and use it in GitHub Desktop.
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