Feature #3622 » net.http.continue.patch
lib/net/http.rb (working copy) | ||
---|---|---|
@started = false
|
||
@open_timeout = nil
|
||
@read_timeout = 60
|
||
@continue_timeout = 0.5
|
||
@debug_output = nil
|
||
@use_ssl = false
|
||
@ssl_context = nil
|
||
... | ... | |
@read_timeout = sec
|
||
end
|
||
# Seconds to wait for 100 Continue response. If the HTTP object does not
|
||
# receive a response in this many seconds it sends the request body.
|
||
attr_reader :continue_timeout
|
||
# Setter for the continue_timeout attribute.
|
||
def continue_timout=(sec)
|
||
@socket.continue_timeout = sec if @socket
|
||
@continue_timeout = sec
|
||
end
|
||
# returns true if the HTTP session is started.
|
||
def started?
|
||
@started
|
||
... | ... | |
def transport_request(req)
|
||
begin_transport req
|
||
req.exec @socket, @curr_http_version, edit_path(req.path)
|
||
res = req.exec @socket, @curr_http_version, edit_path(req.path)
|
||
begin
|
||
res = HTTPResponse.read_new(@socket)
|
||
end while res.kind_of?(HTTPContinue)
|
||
end while res.kind_of?(HTTPContinue) unless res
|
||
res.reading_body(@socket, req.response_body_permitted?) {
|
||
yield res if block_given?
|
||
}
|
||
... | ... | |
delete 'Transfer-Encoding'
|
||
supply_default_content_type
|
||
write_header sock, ver, path
|
||
res = wait_for_continue sock, ver
|
||
return res if res
|
||
sock.write body
|
||
nil
|
||
end
|
||
def send_request_with_body_stream(sock, ver, path, f)
|
||
... | ... | |
end
|
||
supply_default_content_type
|
||
write_header sock, ver, path
|
||
res = wait_for_continue sock, ver
|
||
return res if res
|
||
if chunked?
|
||
while s = f.read(1024)
|
||
sock.write(sprintf("%x\r\n", s.length) << s << "\r\n")
|
||
... | ... | |
sock.write s
|
||
end
|
||
end
|
||
nil
|
||
end
|
||
def supply_default_content_type
|
||
... | ... | |
set_content_type 'application/x-www-form-urlencoded'
|
||
end
|
||
##
|
||
# Waits up to the continue timeout for a response from the server provided
|
||
# we're speaking HTTP 1.1 and are expecting a 100-continue response.
|
||
def wait_for_continue(sock, ver)
|
||
if ver >= '1.1' and @header['expect'] and
|
||
@header['expect'].include?('100-continue') then
|
||
if IO.select [sock.io], nil, nil, sock.continue_timeout then
|
||
res = HTTPResponse.read_new sock
|
||
return res unless res.kind_of?(Net::HTTPContinue)
|
||
end
|
||
end
|
||
nil
|
||
end
|
||
def write_header(sock, ver, path)
|
||
buf = "#{@method} #{path} HTTP/#{ver}\r\n"
|
||
each_capitalized do |k,v|
|
lib/net/protocol.rb (working copy) | ||
---|---|---|
def initialize(io)
|
||
@io = io
|
||
@read_timeout = 60
|
||
@continue_timeout = 0.5
|
||
@debug_output = nil
|
||
@rbuf = ''
|
||
end
|
||
attr_reader :io
|
||
attr_accessor :read_timeout
|
||
attr_accessor :continue_timeout
|
||
attr_accessor :debug_output
|
||
def inspect
|