Parent

Included Modules

Files

HTTPClient::Session

Deprecated. just for backward compatibility


Manages a HTTP session with a Site.

Attributes

connect_retry[RW]
connect_timeout[RW]
debug_dev[RW]

Device for dumping log for debugging

dest[R]

Destination site

protocol_retry_count[RW]
proxy[RW]

Proxy site

read_block_size[RW]
receive_timeout[RW]
requested_version[RW]

Requested protocol version

send_timeout[RW]
socket_sync[RW]

Boolean value for Socket#sync

ssl_config[RW]
ssl_peer_cert[R]
test_loopback_http_response[RW]

Public Class Methods

new(client, dest, agent_name, from) click to toggle source
# 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

Public Instance Methods

close() click to toggle source
# 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
closed?() click to toggle source
# File lib/httpclient/session.rb, line 559
def closed?
  @state == :INIT
end
eof?() click to toggle source
# File lib/httpclient/session.rb, line 576
def eof?
  if !@content_length.nil?
    @content_length == 0
  else
    @socket.closed? or @socket.eof?
  end
end
get_body(&block) click to toggle source
# 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
get_header() click to toggle source
# 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
query(req) click to toggle source

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.