request(req, body = nil)
public
Sends an HTTPRequest object REQUEST to
the HTTP server. This method also sends DATA string if REQUEST is a
post/put request. Giving DATA for
get/head request causes ArgumentError.
When called with a block, yields an HTTPResponse object. The body of this
response will not have been read yet; the caller can process it using
HTTPResponse#read_body, if desired.
Returns a HTTPResponse object.
This method never raises Net::* exceptions.
Show source
def request(req, body = nil, &block)
unless started?
start {
req['connection'] ||= 'close'
return request(req, body, &block)
}
end
if proxy_user()
unless use_ssl?
req.proxy_basic_auth proxy_user(), proxy_pass()
end
end
req.set_body_internal body
begin
begin_transport req
req.exec @socket, @curr_http_version, edit_path(req.path)
begin
res = HTTPResponse.read_new(@socket)
end while res.kind_of?(HTTPContinue)
res.reading_body(@socket, req.response_body_permitted?) {
yield res if block_given?
}
end_transport req, res
rescue => exception
D "Conn close because of error #{exception}"
@socket.close if @socket and not @socket.closed?
raise exception
end
res
end