Class: Syntropy::HTTP::ClientConnection
- Inherits:
-
Object
- Object
- Syntropy::HTTP::ClientConnection
- Defined in:
- lib/syntropy/http/client_connection.rb
Instance Attribute Summary collapse
-
#fd ⇒ Object
readonly
Returns the value of attribute fd.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#response_headers ⇒ Object
readonly
Returns the value of attribute response_headers.
Instance Method Summary collapse
- #get_response_body(headers) ⇒ Object
-
#initialize(machine, fd, io_mode: :socket) ⇒ ClientConnection
constructor
A new instance of ClientConnection.
- #req(body: nil, **headers) ⇒ Object
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
#fd ⇒ Object (readonly)
Returns the value of attribute fd.
9 10 11 |
# File 'lib/syntropy/http/client_connection.rb', line 9 def fd @fd end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/syntropy/http/client_connection.rb', line 9 def logger @logger end |
#response_headers ⇒ Object (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 |