Created
May 26, 2010 22:32
-
-
Save phiggins/415173 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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