Class: Syntropy::HTTP::ClientConnection
- Inherits:
-
Object
- Object
- Syntropy::HTTP::ClientConnection
- Defined in:
- lib/syntropy/http/client_connection.rb
Overview
ClientConnection represents an HTTP client connection.
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) ⇒ String?
Returns the response body.
-
#initialize(machine, fd, io_mode: :socket) ⇒ void
constructor
Initializes a ClientConnection.
-
#req(body: nil, **headers) ⇒ Hash
Performs a request with the given body and headers.
Constructor Details
#initialize(machine, fd, io_mode: :socket) ⇒ void
Initializes a ClientConnection.
18 19 20 21 22 |
# File 'lib/syntropy/http/client_connection.rb', line 18 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.
10 11 12 |
# File 'lib/syntropy/http/client_connection.rb', line 10 def fd @fd end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
10 11 12 |
# File 'lib/syntropy/http/client_connection.rb', line 10 def logger @logger end |
#response_headers ⇒ Object (readonly)
Returns the value of attribute response_headers.
10 11 12 |
# File 'lib/syntropy/http/client_connection.rb', line 10 def response_headers @response_headers end |
Instance Method Details
#get_response_body(headers) ⇒ String?
Returns the response body
47 48 49 |
# File 'lib/syntropy/http/client_connection.rb', line 47 def get_response_body(headers) @io.http_read_body(headers) end |
#req(body: nil, **headers) ⇒ Hash
Performs a request with the given body and headers.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/syntropy/http/client_connection.rb', line 29 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 |