Class: Plum::LegacyClientSession

Inherits:
Object
  • Object
show all
Defined in:
lib/plum/client/legacy_client_session.rb

Overview

HTTP/1.x client session.

Instance Method Summary collapse

Constructor Details

#initialize(socket, config) ⇒ LegacyClientSession

Creates a new HTTP/1.1 client session


6
7
8
9
10
11
12
13
14
15
# File 'lib/plum/client/legacy_client_session.rb', line 6

def initialize(socket, config)
  require "http/parser"
  @socket = socket
  @config = config

  @parser = setup_parser
  @requests = []
  @response = nil
  @headers_callback = nil
end

Instance Method Details

#closeObject


27
28
29
30
# File 'lib/plum/client/legacy_client_session.rb', line 27

def close
  @closed = true
  @response._fail if @response
end

#empty?Boolean

Returns:

  • (Boolean)

23
24
25
# File 'lib/plum/client/legacy_client_session.rb', line 23

def empty?
  !@response
end

#request(headers, body, options, &headers_cb) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/plum/client/legacy_client_session.rb', line 32

def request(headers, body, options, &headers_cb)
  headers["host"] = headers[":authority"] || headers["host"] || @config[:hostname]
  if body
    if headers["content-length"] || headers["transfer-encoding"]
      chunked = false
    else
      chunked = true
      headers["transfer-encoding"] = "chunked"
    end
  end

  response = Response.new
  @requests << [response, headers, body, chunked, headers_cb]
  consume_queue
  response
end

#succObject


17
18
19
20
21
# File 'lib/plum/client/legacy_client_session.rb', line 17

def succ
  @parser << @socket.readpartial(16384)
rescue => e # including HTTP::Parser::Error
  fail(e)
end