lib/excon/response.rb in excon-0.45.4 vs lib/excon/response.rb in excon-0.46.0
- old
+ new
@@ -14,22 +14,25 @@
@data[:headers] = new_headers
end
def headers
@data[:headers]
end
- def status=(new_status)
- @data[:status] = new_status
+ def host
+ @data[:host]
end
- def status
- @data[:status]
+ def local_address
+ @data[:local_address]
end
- def status_line
- @data[:status_line]
+ def local_port
+ @data[:local_port]
end
- def status_line=(new_status_line)
- @data[:status_line] = new_status_line
+ def path
+ @data[:path]
end
+ def port
+ @data[:port]
+ end
def reason_phrase=(new_reason_phrase)
@data[:reason_phrase] = new_reason_phrase
end
def reason_phrase
@data[:reason_phrase]
@@ -38,16 +41,22 @@
@data[:remote_ip] = new_remote_ip
end
def remote_ip
@data[:remote_ip]
end
- def local_port
- @data[:local_port]
+ def status=(new_status)
+ @data[:status] = new_status
end
- def local_address
- @data[:local_address]
+ def status
+ @data[:status]
end
+ def status_line
+ @data[:status_line]
+ end
+ def status_line=(new_status_line)
+ @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 = socket.readline
@@ -55,11 +64,14 @@
reason_phrase = line[13..-3] # -3 strips the trailing "\r\n"
datum[:response] = {
:body => '',
+ :host => datum[:host],
:headers => Excon::Headers.new,
+ :path => datum[:path],
+ :port => datum[:port],
:status => status,
:status_line => line,
:reason_phrase => reason_phrase
}
@@ -98,29 +110,31 @@
if transfer_encoding_chunked
if response_block
while (chunk_size = socket.readline.chomp!.to_i(16)) > 0
while chunk_size > 0
- chunk = socket.read(chunk_size)
+ chunk = socket.read(chunk_size) || raise(EOFError)
chunk_size -= chunk.bytesize
response_block.call(chunk, nil, nil)
end
new_line_size = 2 # 2 == "\r\n".length
while new_line_size > 0
- new_line_size -= socket.read(new_line_size).length
+ chunk = socket.read(new_line_size) || raise(EOFError)
+ new_line_size -= chunk.length
end
end
else
while (chunk_size = socket.readline.chomp!.to_i(16)) > 0
while chunk_size > 0
- chunk = socket.read(chunk_size)
+ chunk = socket.read(chunk_size) || raise(EOFError)
chunk_size -= chunk.bytesize
datum[:response][:body] << chunk
end
new_line_size = 2 # 2 == "\r\n".length
while new_line_size > 0
- new_line_size -= socket.read(new_line_size).length
+ chunk = socket.read(new_line_size) || raise(EOFError)
+ new_line_size -= chunk.length
end
end
end
parse_headers(socket, datum) # merge trailers into headers
else
@@ -129,17 +143,17 @@
end
if remaining = content_length
if response_block
while remaining > 0
- chunk = socket.read([datum[:chunk_size], remaining].min)
+ chunk = socket.read([datum[:chunk_size], remaining].min) || raise(EOFError)
response_block.call(chunk, [remaining - chunk.bytesize, 0].max, content_length)
remaining -= chunk.bytesize
end
else
while remaining > 0
- chunk = socket.read([datum[:chunk_size], remaining].min)
+ chunk = socket.read([datum[:chunk_size], remaining].min) || raise(EOFError)
datum[:response][:body] << chunk
remaining -= chunk.bytesize
end
end
else
@@ -158,10 +172,10 @@
datum
end
def self.parse_headers(socket, datum)
last_key = nil
- until (data = socket.readline.chomp!).empty?
+ until (data = socket.readline.chomp).empty?
if !data.lstrip!.nil?
raise Excon::Errors::ResponseParseError, 'malformed header' unless last_key
# append to last_key's last value
datum[:response][:headers][last_key] << ' ' << data.rstrip
else