Class: Hatetepe::Server::KeepAlive
- Inherits:
-
Object
- Object
- Hatetepe::Server::KeepAlive
- Defined in:
- lib/hatetepe/server/keep_alive.rb
Instance Method Summary collapse
- #call(request, &respond) ⇒ Object
-
#initialize(app, connection) ⇒ KeepAlive
constructor
A new instance of KeepAlive.
- #maybe_close(request, response) ⇒ Object
Constructor Details
#initialize(app, connection) ⇒ KeepAlive
Returns a new instance of KeepAlive.
3 4 5 |
# File 'lib/hatetepe/server/keep_alive.rb', line 3 def initialize(app, connection) @app, @connection = app, connection end |
Instance Method Details
#call(request, &respond) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/hatetepe/server/keep_alive.rb', line 7 def call(request, &respond) @app.call(request) do |response| respond.call(response) maybe_close(request, response) end end |
#maybe_close(request, response) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/hatetepe/server/keep_alive.rb', line 14 def maybe_close(request, response) version = request.http_version.to_f header = request.headers["Connection"] || response.headers["Connection"] if (version < 1.1 && header != "keep-alive") || header == "close" @connection.stop! end end |