lib/excon/response.rb in excon-0.6.5 vs lib/excon/response.rb in excon-0.6.6
- old
+ new
@@ -27,12 +27,10 @@
response.headers[key] = ([*response.headers[key]] << value).compact.join(', ')
if key.casecmp('Content-Length') == 0
content_length = value.to_i
elsif (key.casecmp('Transfer-Encoding') == 0) && (value.casecmp('chunked') == 0)
transfer_encoding_chunked = true
- elsif (key.casecmp('Connection') == 0) && (value.casecmp('close') == 0)
- connection_close = true
end
end
unless (params[:method].to_s.casecmp('HEAD') == 0) || NO_ENTITY.include?(response.status)
@@ -46,46 +44,46 @@
# 2 == "/r/n".length
while (chunk_size = socket.readline.chop!.to_i(16)) > 0
yield(socket.read(chunk_size + 2).chop!, nil, content_length)
end
socket.read(2)
- elsif connection_close
- remaining = socket.read
- yield(remaining, remaining.length, content_length)
- else
+ elsif remaining = content_length
remaining = content_length
while remaining > 0
yield(socket.read([CHUNK_SIZE, remaining].min), [remaining - CHUNK_SIZE, 0].max, content_length)
remaining -= CHUNK_SIZE
end
+ else
+ while remaining = socket.read(CHUNK_SIZE)
+ yield(remaining, remaining.length, content_length)
+ end
end
else
if transfer_encoding_chunked
while (chunk_size = socket.readline.chop!.to_i(16)) > 0
response.body << socket.read(chunk_size + 2).chop! # 2 == "/r/n".length
end
socket.read(2) # 2 == "/r/n".length
- elsif connection_close
- response.body << socket.read
- else
- remaining = content_length
+ elsif remaining = content_length
while remaining > 0
response.body << socket.read([CHUNK_SIZE, remaining].min)
remaining -= CHUNK_SIZE
end
+ else
+ response.body << socket.read
end
end
end
response
end
-
+
# Retrieve a specific header value. Header names are treated case-insensitively.
# @param [String] name Header name
def get_header(name)
headers.each do |key,value|
- if key.casecmp(name) == 0
- return value
+ if key.casecmp(name) == 0
+ return value
end
end
nil
end