Class: Wsv::Server::Connection
- Inherits:
-
Object
- Object
- Wsv::Server::Connection
- Defined in:
- lib/wsv/server/connection.rb
Overview
Owns a single accepted client socket. ‘serve` runs the request lifecycle (parse → app → write → drain → close); `reject` writes 503 (when allowed) and closes. Both share the safe-write / drain / close primitives so a broken peer cannot leak a connection or mask errors.
Constant Summary collapse
- DRAIN_TIMEOUT =
5
Instance Method Summary collapse
-
#initialize(client, err:, cors: nil, access_log: NullAccessLog.new) ⇒ Connection
constructor
A new instance of Connection.
- #reject(reply:) ⇒ Object
- #serve(app, read_timeout:) ⇒ Object
Constructor Details
#initialize(client, err:, cors: nil, access_log: NullAccessLog.new) ⇒ Connection
Returns a new instance of Connection.
17 18 19 20 21 22 23 |
# File 'lib/wsv/server/connection.rb', line 17 def initialize(client, err:, cors: nil, access_log: NullAccessLog.new) @client = client @err = err @cors = cors @access_log = access_log @remote_addr = remote_addr_of(client) end |
Instance Method Details
#reject(reply:) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/wsv/server/connection.rb', line 33 def reject(reply:) response = reply ? Response.text(503) : nil write(response) if response log_access(nil, response) ensure graceful_close end |
#serve(app, read_timeout:) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/wsv/server/connection.rb', line 25 def serve(app, read_timeout:) request, response = process(app, read_timeout) write(response) if response log_access(request, response) ensure graceful_close end |