Class: H2::Server
- Inherits:
-
Object
- Object
- H2::Server
- Includes:
- Celluloid::IO
- Defined in:
- lib/h2/server.rb,
lib/h2/server/https.rb,
lib/h2/server/stream.rb,
lib/h2/server/connection.rb,
lib/h2/server/stream/request.rb,
lib/h2/server/stream/response.rb,
lib/h2/server/stream/event_source.rb,
lib/h2/server/stream/push_promise.rb
Overview
base H2 server, a Celluoid::IO
production
Defined Under Namespace
Modules: ContentEncoder Classes: Connection, HTTP, HTTPS, Stream, StreamError
Constant Summary collapse
- DEFAULT_OPTIONS =
{ backlog: 100, deflate: true, gzip: true }
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#goaway(connection) ⇒ Object
async goaway.
-
#handle_connection(socket) ⇒ Object
build a new connection object, run it through the given block, and start reading from the socket if still attached.
-
#handle_push_promise(push_promise) ⇒ Object
async push promise.
-
#handle_stream(stream) ⇒ Object
async stream handling.
-
#initialize(server, **options, &on_connection) ⇒ Server
constructor
A new instance of Server.
- #shutdown ⇒ Object
Constructor Details
#initialize(server, **options, &on_connection) ⇒ Server
Returns a new instance of Server.
25 26 27 28 29 30 31 32 |
# File 'lib/h2/server.rb', line 25 def initialize server, **, &on_connection @server = server = DEFAULT_OPTIONS.merge @on_connection = on_connection @server.listen [:backlog] async.run end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
23 24 25 |
# File 'lib/h2/server.rb', line 23 def end |
Instance Method Details
#goaway(connection) ⇒ Object
async goaway
61 62 63 64 |
# File 'lib/h2/server.rb', line 61 def goaway connection sleep 0.25 connection.parser.goaway unless connection.closed? end |
#handle_connection(socket) ⇒ Object
build a new connection object, run it through the given block, and start reading from the socket if still attached
41 42 43 44 45 |
# File 'lib/h2/server.rb', line 41 def handle_connection socket connection = H2::Server::Connection.new socket: socket, server: self @on_connection[connection] connection.read if connection.attached? end |
#handle_push_promise(push_promise) ⇒ Object
async push promise
55 56 57 |
# File 'lib/h2/server.rb', line 55 def handle_push_promise push_promise push_promise.keep end |
#handle_stream(stream) ⇒ Object
async stream handling
49 50 51 |
# File 'lib/h2/server.rb', line 49 def handle_stream stream stream.connection.each_stream[stream] end |
#shutdown ⇒ Object
34 35 36 |
# File 'lib/h2/server.rb', line 34 def shutdown @server.close if @server end |