Skip to content

Commit

Permalink
Horrible hack to fix chunked bodies on 1.8.7.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Apr 16, 2012
1 parent 828dd36 commit 900e284
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 6 additions & 4 deletions lib/httparty/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def parser
def perform(&block)
validate
setup_raw_request
chunked_body = nil

self.last_response = http.request(@raw_request) do |http_response|
if block
Expand All @@ -80,12 +81,12 @@ def perform(&block)
block.call(fragment)
end

http_response.body = chunks.join
chunked_body = chunks.join
end
end

handle_deflation
handle_response
handle_response(chunked_body)
end

private
Expand Down Expand Up @@ -196,7 +197,7 @@ def query_string(uri)
query_string_parts.size > 0 ? query_string_parts.join('&') : nil
end

def handle_response
def handle_response(body)
if response_redirects?
options[:limit] -= 1
self.path = last_response['location']
Expand All @@ -205,7 +206,8 @@ def handle_response
capture_cookies(last_response)
perform
else
Response.new(self, last_response, parse_response(last_response.body))
body = body || last_response.body
Response.new(self, last_response, parse_response(body), :body => body)
end
end

Expand Down
12 changes: 6 additions & 6 deletions lib/httparty/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ def self.underscore(string)

attr_reader :request, :response, :parsed_response, :body, :headers

def initialize(request, response, parsed_response)
@request = request
@response = response
@body = response.body
def initialize(request, response, parsed_response, options={})
@request = request
@response = response
@body = response.body || options[:body]
@parsed_response = parsed_response
@headers = Headers.new(response.to_hash)
@headers = Headers.new(response.to_hash)
end

def class
Expand All @@ -64,7 +64,7 @@ def inspect
klass === response
end
end

def respond_to?(name)
return true if [:request,:response,:parsed_response,:body,:headers].include?(name)
parsed_response.respond_to?(name) or response.respond_to?(name)
Expand Down

0 comments on commit 900e284

Please sign in to comment.