lib/excon/response.rb in excon-0.78.1 vs lib/excon/response.rb in excon-0.79.0

- old
+ new

@@ -57,14 +57,17 @@ @data[:status_line] = new_status_line end def self.parse(socket, datum) # this will discard any trailing lines from the previous response if any. - begin + line = nil + loop do line = socket.readline - end until status = line[9, 3].to_i + break if line[9,3].to_i != 0 + end + status = line[9, 3].to_i reason_phrase = line[13..-3] # -3 strips the trailing "\r\n" datum[:response] = { :body => String.new, :cookies => [], @@ -88,11 +91,11 @@ parse_headers(socket, datum) unless (['HEAD', 'CONNECT'].include?(datum[:method].to_s.upcase)) || NO_ENTITY.include?(datum[:response][:status]) - if key = datum[:response][:headers].keys.detect {|k| k.casecmp('Transfer-Encoding') == 0 } + if (key = datum[:response][:headers].keys.detect {|k| k.casecmp('Transfer-Encoding') == 0 }) encodings = Utils.split_header_value(datum[:response][:headers][key]) if (encoding = encodings.last) && encoding.casecmp('chunked') == 0 transfer_encoding_chunked = true if encodings.length == 1 datum[:response][:headers].delete(key) @@ -101,11 +104,11 @@ end end end # use :response_block unless :expects would fail - if response_block = datum[:response_block] + if (response_block = datum[:response_block]) if datum[:middlewares].include?(Excon::Middleware::Expects) && datum[:expects] && !Array(datum[:expects]).include?(datum[:response][:status]) response_block = nil end end @@ -138,15 +141,15 @@ end end end parse_headers(socket, datum) # merge trailers into headers else - if key = datum[:response][:headers].keys.detect {|k| k.casecmp('Content-Length') == 0 } + if (key = datum[:response][:headers].keys.detect {|k| k.casecmp('Content-Length') == 0 }) content_length = datum[:response][:headers][key].to_i end - if remaining = content_length + if (remaining = content_length) if response_block while remaining > 0 chunk = socket.read([datum[:chunk_size], remaining].min) || raise(EOFError) response_block.call(chunk, [remaining - chunk.bytesize, 0].max, content_length) remaining -= chunk.bytesize @@ -158,14 +161,14 @@ remaining -= chunk.bytesize end end else if response_block - while chunk = socket.read(datum[:chunk_size]) + while (chunk = socket.read(datum[:chunk_size])) response_block.call(chunk, nil, nil) end else - while chunk = socket.read(datum[:chunk_size]) + while (chunk = socket.read(datum[:chunk_size])) datum[:response][:body] << chunk end end end end