Class: Syntropy::HTTP::ClientConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/syntropy/http/client_connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine, fd, io_mode: :socket) ⇒ ClientConnection

Returns a new instance of ClientConnection.



11
12
13
14
15
# File 'lib/syntropy/http/client_connection.rb', line 11

def initialize(machine, fd, io_mode: :socket)
  @machine = machine
  @fd = fd
  @io = machine.io(fd, io_mode)
end

Instance Attribute Details

#fdObject (readonly)

Returns the value of attribute fd.



9
10
11
# File 'lib/syntropy/http/client_connection.rb', line 9

def fd
  @fd
end

#loggerObject (readonly)

Returns the value of attribute logger.



9
10
11
# File 'lib/syntropy/http/client_connection.rb', line 9

def logger
  @logger
end

#response_headersObject (readonly)

Returns the value of attribute response_headers.



9
10
11
# File 'lib/syntropy/http/client_connection.rb', line 9

def response_headers
  @response_headers
end

Instance Method Details

#get_response_body(headers) ⇒ Object



31
32
33
# File 'lib/syntropy/http/client_connection.rb', line 31

def get_response_body(headers)
  @io.http_read_body(headers)
end

#req(body: nil, **headers) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/syntropy/http/client_connection.rb', line 17

def req(body: nil, **headers)
  if body
    headers = headers.merge(
      'Content-Length' => body.bytesize
    )
  end
  @io.http_write_request_headers(**headers)
  if body
    @io.write(body)
  end

  @io.http_read_response_headers
end