Device for dumping log for debugging
Destination site
Proxy site
Requested protocol version
Boolean value for Socket#sync
# File lib/httpclient/session.rb, line 567 def initialize(client, dest, agent_name, from) @client = client @dest = dest @invalidated = false @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 @socket_local = Site::EMPTY @agent_name = agent_name @from = from @state = :INIT @requests = [] @status = nil @reason = nil @headers = [] @socket = nil @readbuf = nil @transparent_gzip_decompression = false @last_used = nil end
# File lib/httpclient/session.rb, line 641 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 650 def closed? @state == :INIT end
# File lib/httpclient/session.rb, line 675 def eof? if !@content_length.nil? @content_length == 0 else @socket.closed? or @socket.eof? end end
# File lib/httpclient/session.rb, line 683 def get_body(&block) begin read_header if @state == :META return nil if @state != :DATA if @gzipped and @transparent_gzip_decompression # zlib itself has a functionality to decompress gzip stream. # - zlib 1.2.5 Manual # http://www.zlib.net/manual.html#Advanced # > windowBits can also be greater than 15 for optional gzip decoding. Add 32 to # > windowBits to enable zlib and gzip decoding with automatic header detection, # > or add 16 to decode only the gzip format inflate_stream = Zlib::Inflate.new(Zlib::MAX_WBITS + 32) original_block = block block = Proc.new { |buf| original_block.call(inflate_stream.inflate(buf)) } end 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 662 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
# File lib/httpclient/session.rb, line 654 def invalidate @invalidated = true end
# File lib/httpclient/session.rb, line 658 def invalidated? @invalidated end
Send a request to the server
# File lib/httpclient/session.rb, line 608 def query(req) connect if @state == :INIT # Use absolute URI (not absolute path) iif via proxy AND not HTTPS. req.header.request_absolute_uri = !@proxy.nil? and !https?(@dest) 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, IOError # JRuby can raise IOError instead of ECONNRESET for now close raise KeepAliveDisconnected.new(self) rescue HTTPClient::TimeoutError close raise rescue close if SSLEnabled and $!.is_a?(OpenSSL::SSL::SSLError) raise KeepAliveDisconnected.new(self) else raise end end @state = :META if @state == :WAIT @next_connection = nil @requests.push(req) @last_used = Time.now end