Skip to content

Commit

Permalink
keep @curl around to ensure persistent connections
Browse files Browse the repository at this point in the history
Duh. If you want persistent connections, you've got to keep around
the instance variable.
  • Loading branch information
wmorgan committed Mar 16, 2012
1 parent b453f37 commit 18aa217
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/heliotrope-client.rb
Expand Up @@ -16,6 +16,7 @@ class Error < StandardError; end
def initialize url
@url = url
@cache = LRUCache.new :max_size => 100
@curl = Curl::Easy.new
end

def search query, num=20, start=0
Expand Down Expand Up @@ -96,7 +97,7 @@ def get_json path, params={}

def post_json path, params={}
handle_errors do
ret = Curl::Easy.http_post(URI.join(@url, path + ".json").to_s, URI.encode_www_form(params))
ret = @curl.http_post(URI.join(@url, path + ".json").to_s, URI.encode_www_form(params))
if ret.response_code != 200
raise Error, "Unexpected HTTP response code #{ret.response_code} posting to #{ret.url}"
end
Expand All @@ -107,11 +108,12 @@ def post_json path, params={}
end

def get_binary resource
ret = Curl::Easy.http_get( URI.join(@url, resource).to_s)
if ret.response_code != 200
@curl.url = URI.join(@url, resource).to_s
@curl.http_get
if @curl.response_code != 200
raise Error, "Unexpected HTTP response code #{ret.response_code} getting #{ret.url}"
end
ret.body_str
@curl.body_str
end

def handle_errors
Expand Down

0 comments on commit 18aa217

Please sign in to comment.