Object
# File lib/httpclient/session.rb, line 485 def initialize(client, dest, agent_name, from) @client = client @dest = dest @proxy = nil @socket_sync = true @requested_version = nil @debug_dev = nil @connect_timeout = nil @connect_retry = 1 @send_timeout = nil @receive_timeout = nil @read_block_size = nil @protocol_retry_count = 5 @ssl_config = nil @ssl_peer_cert = nil @test_loopback_http_response = nil @agent_name = agent_name @from = from @state = :INIT @requests = [] @status = nil @reason = nil @headers = [] @socket = nil @readbuf = nil end
# File lib/httpclient/session.rb, line 550 def close if !@socket.nil? and !@socket.closed? # @socket.flush may block when it the socket is already closed by # foreign host and the client runs under MT-condition. @socket.close end @state = :INIT end
# File lib/httpclient/session.rb, line 559 def closed? @state == :INIT end
# File lib/httpclient/session.rb, line 576 def eof? if !@content_length.nil? @content_length == 0 else @socket.closed? or @socket.eof? end end
# File lib/httpclient/session.rb, line 584 def get_body(&block) begin read_header if @state == :META return nil if @state != :DATA if @chunked read_body_chunked(&block) elsif @content_length read_body_length(&block) else read_body_rest(&block) end rescue close raise end if eof? if @next_connection @state = :WAIT else close end end nil end
# File lib/httpclient/session.rb, line 563 def get_header begin if @state != :META raise RuntimeError.new("get_status must be called at the beginning of a session") end read_header rescue close raise end [@version, @status, @reason, @headers] end
Send a request to the server
# File lib/httpclient/session.rb, line 521 def query(req) connect if @state == :INIT req.header.request_via_proxy = !@proxy.nil? begin timeout(@send_timeout, SendTimeoutError) do set_header(req) req.dump(@socket) # flush the IO stream as IO::sync mode is false @socket.flush unless @socket_sync end rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE close raise KeepAliveDisconnected.new rescue HTTPClient::TimeoutError close raise rescue if SSLEnabled and $!.is_a?(OpenSSL::SSL::SSLError) raise KeepAliveDisconnected.new else raise end end @state = :META if @state == :WAIT @next_connection = nil @requests.push(req) end
Generated with the Darkfish Rdoc Generator 2.