raptor 0.20.2 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +28 -17
- data/docs/raptor-vs-puma.md +15 -9
- data/ext/raptor_http2/raptor_http2.c +12 -0
- data/lib/raptor/binder.rb +39 -13
- data/lib/raptor/cli.rb +10 -0
- data/lib/raptor/cluster.rb +5 -3
- data/lib/raptor/http.rb +18 -0
- data/lib/raptor/http1.rb +2 -20
- data/lib/raptor/http2.rb +406 -79
- data/lib/raptor/reactor.rb +142 -23
- data/lib/raptor/server.rb +12 -0
- data/lib/raptor/version.rb +1 -1
- data/sig/generated/raptor/binder.rbs +26 -13
- data/sig/generated/raptor/http.rbs +12 -0
- data/sig/generated/raptor/http1.rbs +0 -12
- data/sig/generated/raptor/http2.rbs +202 -15
- data/sig/generated/raptor/reactor.rbs +70 -8
- metadata +2 -2
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
module Raptor
|
|
4
4
|
# Handles HTTP/2 request processing and Rack application integration.
|
|
5
5
|
class Http2
|
|
6
|
+
RESPONSE_TRAILERS: ::String
|
|
7
|
+
|
|
6
8
|
# Serialises concurrent frame writes on a single HTTP/2 connection so
|
|
7
9
|
# exactly one thread is writing at any moment.
|
|
8
10
|
class Writer
|
|
@@ -31,17 +33,24 @@ module Raptor
|
|
|
31
33
|
def write_frames: (OpenSSL::SSL::SSLSocket socket, Array[String] frames) -> void
|
|
32
34
|
end
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
class StreamClosedError < StandardError
|
|
37
|
+
# @rbs () -> String
|
|
38
|
+
def message: () -> String
|
|
39
|
+
end
|
|
38
40
|
|
|
41
|
+
# Coordinates outbound flow control and stream cancellation without
|
|
42
|
+
# polling or mutexes.
|
|
43
|
+
class FlowControl
|
|
39
44
|
@connection_window: Atom
|
|
40
45
|
|
|
41
46
|
@stream_windows: Atom
|
|
42
47
|
|
|
43
48
|
@initial_stream_window: Atom
|
|
44
49
|
|
|
50
|
+
@cancelled_streams: Atom
|
|
51
|
+
|
|
52
|
+
@available: AtomicConditionVariable
|
|
53
|
+
|
|
45
54
|
# Creates a new FlowControl with the spec-default windows.
|
|
46
55
|
#
|
|
47
56
|
# @return [void]
|
|
@@ -49,17 +58,16 @@ module Raptor
|
|
|
49
58
|
# @rbs () -> void
|
|
50
59
|
def initialize: () -> void
|
|
51
60
|
|
|
52
|
-
# Reserves outbound capacity on the given stream,
|
|
61
|
+
# Reserves outbound capacity on the given stream, waiting until at
|
|
53
62
|
# least one byte is available on both the connection and stream
|
|
54
|
-
# windows.
|
|
63
|
+
# windows. Raises when the stream or connection closes.
|
|
55
64
|
#
|
|
56
65
|
# @param stream_id [Integer] the HTTP/2 stream identifier
|
|
57
66
|
# @param max_bytes [Integer] the largest size the caller would like to send
|
|
58
|
-
# @param end_stream [Boolean] true when this is the final frame on the stream
|
|
59
67
|
# @return [Integer] the number of bytes the caller may now send
|
|
60
68
|
#
|
|
61
|
-
# @rbs (Integer stream_id, Integer max_bytes
|
|
62
|
-
def acquire: (Integer stream_id, Integer max_bytes
|
|
69
|
+
# @rbs (Integer stream_id, Integer max_bytes) -> Integer
|
|
70
|
+
def acquire: (Integer stream_id, Integer max_bytes) -> Integer
|
|
63
71
|
|
|
64
72
|
# Increments the connection-level send window by `increment` bytes.
|
|
65
73
|
#
|
|
@@ -87,6 +95,30 @@ module Raptor
|
|
|
87
95
|
# @rbs (Integer new_size) -> void
|
|
88
96
|
def set_initial_stream_window: (Integer new_size) -> void
|
|
89
97
|
|
|
98
|
+
# Raises when the given stream can no longer write a response.
|
|
99
|
+
#
|
|
100
|
+
# @param stream_id [Integer] the HTTP/2 stream identifier
|
|
101
|
+
# @return [void]
|
|
102
|
+
# @raise [StreamClosedError] if the stream or connection has closed
|
|
103
|
+
#
|
|
104
|
+
# @rbs (Integer stream_id) -> void
|
|
105
|
+
def check: (Integer stream_id) -> void
|
|
106
|
+
|
|
107
|
+
# Cancels pending and future writes for the given stream.
|
|
108
|
+
#
|
|
109
|
+
# @param stream_id [Integer] the HTTP/2 stream identifier
|
|
110
|
+
# @return [void]
|
|
111
|
+
#
|
|
112
|
+
# @rbs (Integer stream_id) -> void
|
|
113
|
+
def cancel_stream: (Integer stream_id) -> void
|
|
114
|
+
|
|
115
|
+
# Cancels pending and future writes for the connection.
|
|
116
|
+
#
|
|
117
|
+
# @return [void]
|
|
118
|
+
#
|
|
119
|
+
# @rbs () -> void
|
|
120
|
+
def close: () -> void
|
|
121
|
+
|
|
90
122
|
# Discards any per-stream tracking for the given stream.
|
|
91
123
|
#
|
|
92
124
|
# @param stream_id [Integer] the HTTP/2 stream identifier
|
|
@@ -108,6 +140,100 @@ module Raptor
|
|
|
108
140
|
def reserve_connection: (Integer capped) -> Integer
|
|
109
141
|
end
|
|
110
142
|
|
|
143
|
+
# Adapts one HTTP/2 response stream to Rack's streaming body interface.
|
|
144
|
+
class ResponseStream
|
|
145
|
+
@closed: bool
|
|
146
|
+
|
|
147
|
+
@bytes_written: Integer
|
|
148
|
+
|
|
149
|
+
@parser: Http2Parser
|
|
150
|
+
|
|
151
|
+
@trailers: Hash[String, String | Array[String]]
|
|
152
|
+
|
|
153
|
+
@stream_id: Integer
|
|
154
|
+
|
|
155
|
+
@flow_control: FlowControl
|
|
156
|
+
|
|
157
|
+
@writer: Writer
|
|
158
|
+
|
|
159
|
+
@socket: OpenSSL::SSL::SSLSocket
|
|
160
|
+
|
|
161
|
+
# Returns the number of response body bytes written to the stream.
|
|
162
|
+
#
|
|
163
|
+
# @return [Integer]
|
|
164
|
+
attr_reader bytes_written: Integer
|
|
165
|
+
|
|
166
|
+
# Creates a response stream for a Rack streaming body.
|
|
167
|
+
#
|
|
168
|
+
# @param socket [OpenSSL::SSL::SSLSocket] the connection socket
|
|
169
|
+
# @param writer [Writer] frame writer for the connection
|
|
170
|
+
# @param flow_control [FlowControl] outbound flow controller
|
|
171
|
+
# @param stream_id [Integer] the HTTP/2 stream identifier
|
|
172
|
+
# @param trailers [Hash] trailing response headers populated by the Rack application
|
|
173
|
+
# @return [void]
|
|
174
|
+
#
|
|
175
|
+
# @rbs (OpenSSL::SSL::SSLSocket socket, Writer writer, FlowControl flow_control, Integer stream_id, Hash[String, String | Array[String]] trailers) -> void
|
|
176
|
+
def initialize: (OpenSSL::SSL::SSLSocket socket, Writer writer, FlowControl flow_control, Integer stream_id, Hash[String, String | Array[String]] trailers) -> void
|
|
177
|
+
|
|
178
|
+
# Streaming responses are write-only.
|
|
179
|
+
#
|
|
180
|
+
# @raise [IOError]
|
|
181
|
+
#
|
|
182
|
+
# @rbs (*untyped) -> bot
|
|
183
|
+
def read: (*untyped) -> bot
|
|
184
|
+
|
|
185
|
+
# Writes response body bytes to the stream.
|
|
186
|
+
#
|
|
187
|
+
# @param chunk [String] response body bytes
|
|
188
|
+
# @return [Integer] number of bytes written
|
|
189
|
+
#
|
|
190
|
+
# @rbs (String chunk) -> Integer
|
|
191
|
+
def write: (String chunk) -> Integer
|
|
192
|
+
|
|
193
|
+
# Writes response body bytes and returns the stream.
|
|
194
|
+
#
|
|
195
|
+
# @param chunk [String] response body bytes
|
|
196
|
+
# @return [ResponseStream]
|
|
197
|
+
#
|
|
198
|
+
# @rbs (String chunk) -> ResponseStream
|
|
199
|
+
def <<: (String chunk) -> ResponseStream
|
|
200
|
+
|
|
201
|
+
# Flushes the stream. Frame writes are already immediate.
|
|
202
|
+
#
|
|
203
|
+
# @return [ResponseStream]
|
|
204
|
+
#
|
|
205
|
+
# @rbs () -> ResponseStream
|
|
206
|
+
def flush: () -> ResponseStream
|
|
207
|
+
|
|
208
|
+
# Finishes the stream.
|
|
209
|
+
#
|
|
210
|
+
# @return [void]
|
|
211
|
+
#
|
|
212
|
+
# @rbs () -> void
|
|
213
|
+
def close: () -> void
|
|
214
|
+
|
|
215
|
+
# Closes the unsupported read side of the stream.
|
|
216
|
+
#
|
|
217
|
+
# @raise [IOError]
|
|
218
|
+
#
|
|
219
|
+
# @rbs () -> bot
|
|
220
|
+
def close_read: () -> bot
|
|
221
|
+
|
|
222
|
+
# Finishes the writable side of the stream.
|
|
223
|
+
#
|
|
224
|
+
# @return [void]
|
|
225
|
+
#
|
|
226
|
+
# @rbs () -> void
|
|
227
|
+
def close_write: () -> void
|
|
228
|
+
|
|
229
|
+
# Returns whether the stream has finished.
|
|
230
|
+
#
|
|
231
|
+
# @return [Boolean]
|
|
232
|
+
#
|
|
233
|
+
# @rbs () -> bool
|
|
234
|
+
def closed?: () -> bool
|
|
235
|
+
end
|
|
236
|
+
|
|
111
237
|
EAGER_READ_TIMEOUT: ::Float
|
|
112
238
|
|
|
113
239
|
EAGER_READ_BUFFER_SIZE: untyped
|
|
@@ -126,6 +252,10 @@ module Raptor
|
|
|
126
252
|
|
|
127
253
|
ERROR_PROTOCOL_ERROR: ::Integer
|
|
128
254
|
|
|
255
|
+
ERROR_INTERNAL_ERROR: ::Integer
|
|
256
|
+
|
|
257
|
+
ERROR_REFUSED_STREAM: ::Integer
|
|
258
|
+
|
|
129
259
|
DEFAULT_WINDOW_SIZE: ::Integer
|
|
130
260
|
|
|
131
261
|
MAX_FRAME_SIZE: ::Integer
|
|
@@ -148,6 +278,8 @@ module Raptor
|
|
|
148
278
|
# @rbs (Array[[String, String]] headers) -> bool
|
|
149
279
|
def self.invalid_pseudo_headers?: (Array[[ String, String ]] headers) -> bool
|
|
150
280
|
|
|
281
|
+
@running: AtomicBoolean
|
|
282
|
+
|
|
151
283
|
@initial_settings_frame: String
|
|
152
284
|
|
|
153
285
|
@on_error: ^(Hash[String, untyped]?, Exception) -> void | nil
|
|
@@ -194,6 +326,15 @@ module Raptor
|
|
|
194
326
|
# @rbs () -> Writer
|
|
195
327
|
def create_writer: () -> Writer
|
|
196
328
|
|
|
329
|
+
# Stops new stream dispatch and asks clients to finish streams already
|
|
330
|
+
# handed to the application.
|
|
331
|
+
#
|
|
332
|
+
# @param reactor [Reactor] the reactor managing HTTP/2 connections
|
|
333
|
+
# @return [void]
|
|
334
|
+
#
|
|
335
|
+
# @rbs (Reactor reactor) -> void
|
|
336
|
+
def shutdown: (Reactor reactor) -> void
|
|
337
|
+
|
|
197
338
|
# Returns a Ractor-safe proc that parses HTTP/2 frames from the
|
|
198
339
|
# state hash's buffered bytes.
|
|
199
340
|
#
|
|
@@ -212,6 +353,22 @@ module Raptor
|
|
|
212
353
|
# @rbs (Hash[Symbol, untyped] data) -> Hash[Symbol, untyped]
|
|
213
354
|
def self.process_frames: (Hash[Symbol, untyped] data) -> Hash[Symbol, untyped]
|
|
214
355
|
|
|
356
|
+
# Applies one complete request header block to its stream, resetting
|
|
357
|
+
# malformed initial headers or trailers and completing valid trailers.
|
|
358
|
+
#
|
|
359
|
+
# @param streams [Hash] current open-stream map
|
|
360
|
+
# @param completed_requests [Array<Hash>] accumulator of completed stream requests
|
|
361
|
+
# @param outgoing_frames [Array<String>] accumulator of protocol response frames
|
|
362
|
+
# @param parser [Http2Parser] frame parser and encoder
|
|
363
|
+
# @param stream_id [Integer] the stream identifier
|
|
364
|
+
# @param decoded_headers [Array<Array(String, String)>] decoded header pairs
|
|
365
|
+
# @param end_stream [Boolean] whether the source frame had END_STREAM set
|
|
366
|
+
# @param trailers [Boolean] whether this is a trailing header block
|
|
367
|
+
# @return [Array(Hash, Array<Hash>)] updated streams and completed requests
|
|
368
|
+
#
|
|
369
|
+
# @rbs (Hash[Integer, Hash[Symbol, untyped]] streams, Array[Hash[Symbol, untyped]] completed_requests, Array[String] outgoing_frames, Http2Parser parser, Integer stream_id, Array[[String, String]] decoded_headers, bool end_stream, bool trailers) -> [Hash[Integer, Hash[Symbol, untyped]], Array[Hash[Symbol, untyped]]]
|
|
370
|
+
def self.complete_header_block: (Hash[Integer, Hash[Symbol, untyped]] streams, Array[Hash[Symbol, untyped]] completed_requests, Array[String] outgoing_frames, Http2Parser parser, Integer stream_id, Array[[ String, String ]] decoded_headers, bool end_stream, bool trailers) -> [ Hash[Integer, Hash[Symbol, untyped]], Array[Hash[Symbol, untyped]] ]
|
|
371
|
+
|
|
215
372
|
# Merges a decoded header block into the stream's accumulated state,
|
|
216
373
|
# promoting the stream to `completed_requests` when END_STREAM is set.
|
|
217
374
|
#
|
|
@@ -233,7 +390,9 @@ module Raptor
|
|
|
233
390
|
# @param streams [Hash] updated stream states
|
|
234
391
|
# @param outgoing_frames [Array<String>] frames to write to the socket
|
|
235
392
|
# @param completed_requests [Array<Hash>] fully received stream requests
|
|
393
|
+
# @param cancelled_streams [Array<Integer>] streams reset by the peer
|
|
236
394
|
# @param window_updates [Array<Array(Integer, Integer)>] inbound WINDOW_UPDATE pairs as [stream_id, increment]
|
|
395
|
+
# @param ping_acknowledgements [Array<String>] acknowledged PING payloads
|
|
237
396
|
# @param peer_initial_window_size [Integer, nil] new SETTINGS_INITIAL_WINDOW_SIZE announced by the peer
|
|
238
397
|
# @param connection_window [Integer] current connection flow control window
|
|
239
398
|
# @param preface_received [Boolean] whether the connection preface has been received
|
|
@@ -242,8 +401,8 @@ module Raptor
|
|
|
242
401
|
# @param close_connection [Boolean] whether the connection should be closed after writing outgoing frames
|
|
243
402
|
# @return [Hash] frozen result hash
|
|
244
403
|
#
|
|
245
|
-
# @rbs (Hash[Symbol, untyped] data, String buffer, Array[untyped] hpack_table, Hash[Integer, Hash[Symbol, untyped]] streams, Array[String] outgoing_frames, Array[Hash[Symbol, untyped]] completed_requests, Array[[Integer, Integer]] window_updates, Integer? peer_initial_window_size, Integer connection_window, bool preface_received, Integer last_client_stream_id, Hash[Symbol, untyped]? pending_headers, bool close_connection) -> Hash[Symbol, untyped]
|
|
246
|
-
def self.build_result: (Hash[Symbol, untyped] data, String buffer, Array[untyped] hpack_table, Hash[Integer, Hash[Symbol, untyped]] streams, Array[String] outgoing_frames, Array[Hash[Symbol, untyped]] completed_requests, Array[[ Integer, Integer ]] window_updates, Integer? peer_initial_window_size, Integer connection_window, bool preface_received, Integer last_client_stream_id, Hash[Symbol, untyped]? pending_headers, bool close_connection) -> Hash[Symbol, untyped]
|
|
404
|
+
# @rbs (Hash[Symbol, untyped] data, String buffer, Array[untyped] hpack_table, Hash[Integer, Hash[Symbol, untyped]] streams, Array[String] outgoing_frames, Array[Hash[Symbol, untyped]] completed_requests, Array[Integer] cancelled_streams, Array[[Integer, Integer]] window_updates, Array[String] ping_acknowledgements, Integer? peer_initial_window_size, Integer connection_window, bool preface_received, Integer last_client_stream_id, Hash[Symbol, untyped]? pending_headers, bool close_connection) -> Hash[Symbol, untyped]
|
|
405
|
+
def self.build_result: (Hash[Symbol, untyped] data, String buffer, Array[untyped] hpack_table, Hash[Integer, Hash[Symbol, untyped]] streams, Array[String] outgoing_frames, Array[Hash[Symbol, untyped]] completed_requests, Array[Integer] cancelled_streams, Array[[ Integer, Integer ]] window_updates, Array[String] ping_acknowledgements, Integer? peer_initial_window_size, Integer connection_window, bool preface_received, Integer last_client_stream_id, Hash[Symbol, untyped]? pending_headers, bool close_connection) -> Hash[Symbol, untyped]
|
|
247
406
|
|
|
248
407
|
# Sends the server SETTINGS frame on a freshly negotiated HTTP/2
|
|
249
408
|
# connection, then eagerly reads and parses the first client frame
|
|
@@ -325,10 +484,35 @@ module Raptor
|
|
|
325
484
|
# @param status [Integer] HTTP status code
|
|
326
485
|
# @param headers [Hash] response headers from the Rack application
|
|
327
486
|
# @param body [Object] response body responding to each
|
|
487
|
+
# @param trailers [Hash] trailing response headers populated by the Rack application
|
|
488
|
+
# @param request_method [String] request method used to suppress HEAD response bodies
|
|
328
489
|
# @return [String] the response body size in bytes
|
|
329
490
|
#
|
|
330
|
-
# @rbs (OpenSSL::SSL::SSLSocket socket, Writer writer, FlowControl flow_control, Integer stream_id, Integer status, Hash[String, String | Array[String]] headers, untyped body) -> String
|
|
331
|
-
def write_http2_response: (OpenSSL::SSL::SSLSocket socket, Writer writer, FlowControl flow_control, Integer stream_id, Integer status, Hash[String, String | Array[String]] headers, untyped body) -> String
|
|
491
|
+
# @rbs (OpenSSL::SSL::SSLSocket socket, Writer writer, FlowControl flow_control, Integer stream_id, Integer status, Hash[String, String | Array[String]] headers, untyped body, trailers: Hash[String, String | Array[String]], request_method: String) ?{ () -> void } -> String
|
|
492
|
+
def write_http2_response: (OpenSSL::SSL::SSLSocket socket, Writer writer, FlowControl flow_control, Integer stream_id, Integer status, Hash[String, String | Array[String]] headers, untyped body, trailers: Hash[String, String | Array[String]], request_method: String) ?{ () -> void } -> String
|
|
493
|
+
|
|
494
|
+
# Sends an HTTP 103 Early Hints response.
|
|
495
|
+
#
|
|
496
|
+
# @param socket [OpenSSL::SSL::SSLSocket] the connection socket
|
|
497
|
+
# @param writer [Writer] frame writer for the connection
|
|
498
|
+
# @param flow_control [FlowControl] per-connection outbound flow controller
|
|
499
|
+
# @param stream_id [Integer] the HTTP/2 stream identifier
|
|
500
|
+
# @param hints [Hash] response headers to send as early hints
|
|
501
|
+
# @return [void]
|
|
502
|
+
#
|
|
503
|
+
# @rbs (OpenSSL::SSL::SSLSocket socket, Writer writer, FlowControl flow_control, Integer stream_id, Hash[String, String | Array[String]] hints) -> void
|
|
504
|
+
def send_early_hints: (OpenSSL::SSL::SSLSocket socket, Writer writer, FlowControl flow_control, Integer stream_id, Hash[String, String | Array[String]] hints) -> void
|
|
505
|
+
|
|
506
|
+
# Resets one HTTP/2 stream with the given error code.
|
|
507
|
+
#
|
|
508
|
+
# @param socket [OpenSSL::SSL::SSLSocket] the connection socket
|
|
509
|
+
# @param writer [Writer] frame writer for the connection
|
|
510
|
+
# @param stream_id [Integer] the HTTP/2 stream identifier
|
|
511
|
+
# @param error_code [Integer] the HTTP/2 error code
|
|
512
|
+
# @return [void]
|
|
513
|
+
#
|
|
514
|
+
# @rbs (OpenSSL::SSL::SSLSocket socket, Writer writer, Integer stream_id, Integer error_code) -> void
|
|
515
|
+
def write_http2_reset_stream: (OpenSSL::SSL::SSLSocket socket, Writer writer, Integer stream_id, Integer error_code) -> void
|
|
332
516
|
|
|
333
517
|
# Writes a 500 error response as HTTP/2 frames.
|
|
334
518
|
#
|
|
@@ -356,11 +540,14 @@ module Raptor
|
|
|
356
540
|
#
|
|
357
541
|
# @param headers [Array<Array(String, String)>] HTTP/2 header pairs
|
|
358
542
|
# @param body [String] the request body
|
|
543
|
+
# @param socket [OpenSSL::SSL::SSLSocket] the connection socket
|
|
544
|
+
# @param writer [Writer] frame writer for the connection
|
|
545
|
+
# @param stream_id [Integer] the HTTP/2 stream identifier
|
|
359
546
|
# @param remote_addr [String] the client IP address
|
|
360
547
|
# @return [Hash] fully populated Rack environment hash
|
|
361
548
|
#
|
|
362
|
-
# @rbs (Array[[String, String]] headers, String body, remote_addr: String) -> Hash[String, untyped]
|
|
363
|
-
def build_rack_env: (Array[[ String, String ]] headers, String body, remote_addr: String) -> Hash[String, untyped]
|
|
549
|
+
# @rbs (Array[[String, String]] headers, String body, OpenSSL::SSL::SSLSocket socket, Writer writer, FlowControl flow_control, Integer stream_id, remote_addr: String) -> Hash[String, untyped]
|
|
550
|
+
def build_rack_env: (Array[[ String, String ]] headers, String body, OpenSSL::SSL::SSLSocket socket, Writer writer, FlowControl flow_control, Integer stream_id, remote_addr: String) -> Hash[String, untyped]
|
|
364
551
|
|
|
365
552
|
# Populates SERVER_NAME and SERVER_PORT from the HTTP_HOST header.
|
|
366
553
|
#
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# Generated from lib/raptor/reactor.rb with RBS::Inline
|
|
2
2
|
|
|
3
3
|
module Raptor
|
|
4
|
-
# Multiplexes client connections
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
# completed requests back to the caller-provided handlers.
|
|
4
|
+
# Multiplexes client connections, manages connection deadlines, feeds
|
|
5
|
+
# ready bytes to the parser pipeline, and hands completed requests back
|
|
6
|
+
# to the caller-provided handlers.
|
|
8
7
|
class Reactor
|
|
9
8
|
# A client connection node ordered by absolute expiry time so the
|
|
10
9
|
# soonest-to-expire is always at the tree's minimum.
|
|
@@ -54,6 +53,10 @@ module Raptor
|
|
|
54
53
|
|
|
55
54
|
@persistent_data_timeout: Integer
|
|
56
55
|
|
|
56
|
+
@http2_keepalive_interval: Integer
|
|
57
|
+
|
|
58
|
+
@http2_keepalive_timeout: Integer
|
|
59
|
+
|
|
57
60
|
@selector: NIO::Selector
|
|
58
61
|
|
|
59
62
|
@queue: Queue[TCPSocket]
|
|
@@ -70,6 +73,12 @@ module Raptor
|
|
|
70
73
|
|
|
71
74
|
@id_to_flow_control: Hash[Integer, untyped]
|
|
72
75
|
|
|
76
|
+
@id_to_http2_last_stream: Hash[Integer, Integer]
|
|
77
|
+
|
|
78
|
+
@id_to_http2_drain_stream: Hash[Integer, Integer]
|
|
79
|
+
|
|
80
|
+
@id_to_http2_keepalive: Hash[Integer, Hash[Symbol, untyped]]
|
|
81
|
+
|
|
73
82
|
# Creates a new Reactor instance.
|
|
74
83
|
#
|
|
75
84
|
# @param http1_ractor_pool [RactorPool] ractor pool for HTTP/1.x parsing
|
|
@@ -80,10 +89,13 @@ module Raptor
|
|
|
80
89
|
# @option connection_options [Integer] :chunk_data_timeout timeout for subsequent chunks
|
|
81
90
|
# @param http1_options [Hash] HTTP/1.1-specific configuration
|
|
82
91
|
# @option http1_options [Integer] :persistent_data_timeout timeout for keep-alive idle connections
|
|
92
|
+
# @param http2_options [Hash] HTTP/2-specific configuration
|
|
93
|
+
# @option http2_options [Integer] :keepalive_interval idle time before sending a PING
|
|
94
|
+
# @option http2_options [Integer] :keepalive_timeout time to await a PING acknowledgement
|
|
83
95
|
# @return [void]
|
|
84
96
|
#
|
|
85
|
-
# @rbs (untyped http1_ractor_pool, untyped http2_ractor_pool, untyped thread_pool, connection_options: Hash[Symbol, untyped], http1_options: Hash[Symbol, untyped]) -> void
|
|
86
|
-
def initialize: (untyped http1_ractor_pool, untyped http2_ractor_pool, untyped thread_pool, connection_options: Hash[Symbol, untyped], http1_options: Hash[Symbol, untyped]) -> void
|
|
97
|
+
# @rbs (untyped http1_ractor_pool, untyped http2_ractor_pool, untyped thread_pool, connection_options: Hash[Symbol, untyped], http1_options: Hash[Symbol, untyped], http2_options: Hash[Symbol, untyped]) -> void
|
|
98
|
+
def initialize: (untyped http1_ractor_pool, untyped http2_ractor_pool, untyped thread_pool, connection_options: Hash[Symbol, untyped], http1_options: Hash[Symbol, untyped], http2_options: Hash[Symbol, untyped]) -> void
|
|
87
99
|
|
|
88
100
|
# Starts the reactor's main event loop in a new thread. Runs until
|
|
89
101
|
# the registration queue is closed and drained.
|
|
@@ -162,6 +174,26 @@ module Raptor
|
|
|
162
174
|
# @rbs (Integer id) -> untyped?
|
|
163
175
|
def flow_control_for: (Integer id) -> untyped?
|
|
164
176
|
|
|
177
|
+
# Records an HTTP/2 stream before application dispatch, rejecting streams
|
|
178
|
+
# that arrived after graceful draining began.
|
|
179
|
+
#
|
|
180
|
+
# @param id [Integer] unique connection identifier
|
|
181
|
+
# @param stream_id [Integer] HTTP/2 stream identifier
|
|
182
|
+
# @return [Boolean] whether the stream may be dispatched
|
|
183
|
+
#
|
|
184
|
+
# @rbs (Integer id, Integer stream_id) -> bool
|
|
185
|
+
def dispatch_http2_stream: (Integer id, Integer stream_id) -> bool
|
|
186
|
+
|
|
187
|
+
# Sends GOAWAY on every HTTP/2 connection and fixes the last stream each
|
|
188
|
+
# connection may dispatch while existing application work drains.
|
|
189
|
+
#
|
|
190
|
+
# @yieldparam stream_id [Integer] last dispatched stream identifier
|
|
191
|
+
# @yieldreturn [String] serialized GOAWAY frame
|
|
192
|
+
# @return [void]
|
|
193
|
+
#
|
|
194
|
+
# @rbs () { (Integer stream_id) -> String } -> void
|
|
195
|
+
def drain_http2: () { (Integer stream_id) -> String } -> void
|
|
196
|
+
|
|
165
197
|
# Stores an HTTP/2 connection's socket, state, writer, and flow
|
|
166
198
|
# controller in the reactor's per-connection maps.
|
|
167
199
|
#
|
|
@@ -170,10 +202,21 @@ module Raptor
|
|
|
170
202
|
# @param state [Hash] initial connection state
|
|
171
203
|
# @param writer [Http2::Writer] per-connection frame writer
|
|
172
204
|
# @param flow_control [Http2::FlowControl] per-connection outbound flow controller
|
|
205
|
+
# @param ping_frame [String] serialized PING frame for keepalive probes
|
|
206
|
+
# @param ping_payload [String] payload expected in the corresponding acknowledgement
|
|
173
207
|
# @return [void]
|
|
174
208
|
#
|
|
175
|
-
# @rbs (id: Integer, socket: TCPSocket, state: Hash[Symbol, untyped], writer: untyped, flow_control: untyped) -> void
|
|
176
|
-
def attach_http2: (id: Integer, socket: TCPSocket, state: Hash[Symbol, untyped], writer: untyped, flow_control: untyped) -> void
|
|
209
|
+
# @rbs (id: Integer, socket: TCPSocket, state: Hash[Symbol, untyped], writer: untyped, flow_control: untyped, ping_frame: String, ping_payload: String) -> void
|
|
210
|
+
def attach_http2: (id: Integer, socket: TCPSocket, state: Hash[Symbol, untyped], writer: untyped, flow_control: untyped, ping_frame: String, ping_payload: String) -> void
|
|
211
|
+
|
|
212
|
+
# Records acknowledgements for server keepalive probes.
|
|
213
|
+
#
|
|
214
|
+
# @param id [Integer] unique connection identifier
|
|
215
|
+
# @param payloads [Array<String>, nil] acknowledged PING payloads
|
|
216
|
+
# @return [void]
|
|
217
|
+
#
|
|
218
|
+
# @rbs (Integer id, Array[String]? payloads) -> void
|
|
219
|
+
def acknowledge_http2_ping: (Integer id, Array[String]? payloads) -> void
|
|
177
220
|
|
|
178
221
|
# Registers an attached socket for future reactor-driven reads.
|
|
179
222
|
#
|
|
@@ -227,6 +270,25 @@ module Raptor
|
|
|
227
270
|
# @rbs (TCPSocket socket) -> void
|
|
228
271
|
def register: (TCPSocket socket) -> void
|
|
229
272
|
|
|
273
|
+
# Adds a connection deadline to the timeout tree.
|
|
274
|
+
#
|
|
275
|
+
# @param state [Hash] client connection state
|
|
276
|
+
# @param timeout_at [Float] absolute monotonic expiry time
|
|
277
|
+
# @return [void]
|
|
278
|
+
#
|
|
279
|
+
# @rbs (Hash[Symbol, untyped] state, Float timeout_at) -> void
|
|
280
|
+
def track_timeout: (Hash[Symbol, untyped] state, Float timeout_at) -> void
|
|
281
|
+
|
|
282
|
+
# Handles an expired connection deadline, sending an HTTP/2 keepalive
|
|
283
|
+
# probe before closing the connection when its acknowledgement is late.
|
|
284
|
+
#
|
|
285
|
+
# @param client [TimeoutClient] expired client
|
|
286
|
+
# @param now [Float] current monotonic timestamp
|
|
287
|
+
# @return [void]
|
|
288
|
+
#
|
|
289
|
+
# @rbs (TimeoutClient client, Float now) -> void
|
|
290
|
+
def handle_timeout: (TimeoutClient client, Float now) -> void
|
|
291
|
+
|
|
230
292
|
# Handles socket wakeup by deregistering and queuing for processing.
|
|
231
293
|
#
|
|
232
294
|
# @param socket [TCPSocket] the socket that became ready
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: raptor
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.21.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joshua Young
|
|
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
206
206
|
- !ruby/object:Gem::Version
|
|
207
207
|
version: '0'
|
|
208
208
|
requirements: []
|
|
209
|
-
rubygems_version: 4.0.
|
|
209
|
+
rubygems_version: 4.0.20
|
|
210
210
|
specification_version: 4
|
|
211
211
|
summary: "A high-performance Ruby web server (rawr \U0001F996)"
|
|
212
212
|
test_files: []
|