protocol-http2 0.14.2 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/protocol/http2/client.rb +4 -23
- data/lib/protocol/http2/connection.rb +32 -52
- data/lib/protocol/http2/continuation_frame.rb +9 -20
- data/lib/protocol/http2/data_frame.rb +5 -21
- data/lib/protocol/http2/dependency.rb +9 -24
- data/lib/protocol/http2/error.rb +10 -25
- data/lib/protocol/http2/flow_controlled.rb +5 -19
- data/lib/protocol/http2/frame.rb +23 -28
- data/lib/protocol/http2/framer.rb +8 -24
- data/lib/protocol/http2/goaway_frame.rb +4 -19
- data/lib/protocol/http2/headers_frame.rb +5 -20
- data/lib/protocol/http2/padded.rb +5 -21
- data/lib/protocol/http2/ping_frame.rb +12 -19
- data/lib/protocol/http2/priority_frame.rb +4 -23
- data/lib/protocol/http2/push_promise_frame.rb +4 -19
- data/lib/protocol/http2/reset_stream_frame.rb +4 -19
- data/lib/protocol/http2/server.rb +5 -20
- data/lib/protocol/http2/settings_frame.rb +22 -34
- data/lib/protocol/http2/stream.rb +11 -23
- data/lib/protocol/http2/version.rb +5 -20
- data/lib/protocol/http2/window_update_frame.rb +23 -26
- data/lib/protocol/http2.rb +4 -19
- data/license.md +24 -0
- data/readme.md +98 -0
- data.tar.gz.sig +3 -0
- metadata +44 -10
- metadata.gz.sig +0 -0
@@ -1,22 +1,7 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
20
5
|
|
21
6
|
require_relative 'frame'
|
22
7
|
|
@@ -29,6 +14,10 @@ module Protocol
|
|
29
14
|
flag_set?(ACKNOWLEDGEMENT)
|
30
15
|
end
|
31
16
|
|
17
|
+
def acknowledgement!
|
18
|
+
set_flags(ACKNOWLEDGEMENT)
|
19
|
+
end
|
20
|
+
|
32
21
|
def acknowledge
|
33
22
|
frame = self.class.new
|
34
23
|
|
@@ -71,6 +60,10 @@ module Protocol
|
|
71
60
|
def read_payload(stream)
|
72
61
|
super
|
73
62
|
|
63
|
+
if @stream_id != 0
|
64
|
+
raise ProtocolError, "Settings apply to connection only, but stream_id was given"
|
65
|
+
end
|
66
|
+
|
74
67
|
if @length != 8
|
75
68
|
raise FrameSizeError, "Invalid frame length: #{@length} != 8!"
|
76
69
|
end
|
@@ -1,22 +1,7 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
20
5
|
|
21
6
|
require_relative 'frame'
|
22
7
|
|
@@ -73,10 +58,6 @@ module Protocol
|
|
73
58
|
class PriorityFrame < Frame
|
74
59
|
TYPE = 0x2
|
75
60
|
|
76
|
-
def priority
|
77
|
-
Priority.unpack(@payload)
|
78
|
-
end
|
79
|
-
|
80
61
|
def pack priority
|
81
62
|
super priority.pack
|
82
63
|
end
|
@@ -1,22 +1,7 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
20
5
|
|
21
6
|
require_relative 'frame'
|
22
7
|
require_relative 'padded'
|
@@ -1,22 +1,7 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
20
5
|
|
21
6
|
require_relative 'frame'
|
22
7
|
|
@@ -1,22 +1,7 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
20
5
|
|
21
6
|
require_relative 'connection'
|
22
7
|
|
@@ -49,7 +34,7 @@ module Protocol
|
|
49
34
|
raise ProtocolError, "First frame must be #{SettingsFrame}, but got #{frame.class}" unless frame.is_a? SettingsFrame
|
50
35
|
end
|
51
36
|
else
|
52
|
-
raise ProtocolError, "Cannot
|
37
|
+
raise ProtocolError, "Cannot read connection preface in state #{@state}"
|
53
38
|
end
|
54
39
|
end
|
55
40
|
|
@@ -1,22 +1,7 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
20
5
|
|
21
6
|
require_relative 'ping_frame'
|
22
7
|
|
@@ -31,6 +16,18 @@ module Protocol
|
|
31
16
|
MAXIMUM_HEADER_LIST_SIZE = 0x6
|
32
17
|
ENABLE_CONNECT_PROTOCOL = 0x8
|
33
18
|
|
19
|
+
ASSIGN = [
|
20
|
+
nil,
|
21
|
+
:header_table_size=,
|
22
|
+
:enable_push=,
|
23
|
+
:maximum_concurrent_streams=,
|
24
|
+
:initial_window_size=,
|
25
|
+
:maximum_frame_size=,
|
26
|
+
:maximum_header_list_size=,
|
27
|
+
nil,
|
28
|
+
:enable_connect_protocol=,
|
29
|
+
]
|
30
|
+
|
34
31
|
# Allows the sender to inform the remote endpoint of the maximum size of the header compression table used to decode header blocks, in octets.
|
35
32
|
attr_accessor :header_table_size
|
36
33
|
|
@@ -59,8 +56,7 @@ module Protocol
|
|
59
56
|
if value <= MAXIMUM_ALLOWED_WINDOW_SIZE
|
60
57
|
@initial_window_size = value
|
61
58
|
else
|
62
|
-
|
63
|
-
raise FlowControlError, "Invalid value for initial_window_size: #{value} > #{MAXIMUM_ALLOWED_WINDOW_SIZE}"
|
59
|
+
raise ProtocolError, "Invalid value for initial_window_size: #{value} > #{MAXIMUM_ALLOWED_WINDOW_SIZE}"
|
64
60
|
end
|
65
61
|
end
|
66
62
|
|
@@ -106,18 +102,6 @@ module Protocol
|
|
106
102
|
@enable_connect_protocol = 0
|
107
103
|
end
|
108
104
|
|
109
|
-
ASSIGN = [
|
110
|
-
nil,
|
111
|
-
:header_table_size=,
|
112
|
-
:enable_push=,
|
113
|
-
:maximum_concurrent_streams=,
|
114
|
-
:initial_window_size=,
|
115
|
-
:maximum_frame_size=,
|
116
|
-
:maximum_header_list_size=,
|
117
|
-
nil, nil,
|
118
|
-
:enable_connect_protocol=,
|
119
|
-
]
|
120
|
-
|
121
105
|
def update(changes)
|
122
106
|
changes.each do |key, value|
|
123
107
|
if name = ASSIGN[key]
|
@@ -134,7 +118,7 @@ module Protocol
|
|
134
118
|
end
|
135
119
|
|
136
120
|
if @enable_push != other.enable_push
|
137
|
-
changes << [ENABLE_PUSH, @enable_push
|
121
|
+
changes << [ENABLE_PUSH, @enable_push]
|
138
122
|
end
|
139
123
|
|
140
124
|
if @maximum_concurrent_streams != other.maximum_concurrent_streams
|
@@ -210,6 +194,10 @@ module Protocol
|
|
210
194
|
def maximum_header_list_size
|
211
195
|
@current.maximum_header_list_size
|
212
196
|
end
|
197
|
+
|
198
|
+
def enable_connect_protocol
|
199
|
+
@current.enable_connect_protocol
|
200
|
+
end
|
213
201
|
end
|
214
202
|
|
215
203
|
# The SETTINGS frame conveys configuration parameters that affect how endpoints communicate, such as preferences and constraints on peer behavior. The SETTINGS frame is also used to acknowledge the receipt of those parameters. Individually, a SETTINGS parameter can also be referred to as a "setting".
|
@@ -1,22 +1,7 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
20
5
|
|
21
6
|
require_relative 'connection'
|
22
7
|
require_relative 'dependency'
|
@@ -149,6 +134,7 @@ module Protocol
|
|
149
134
|
end
|
150
135
|
end
|
151
136
|
|
137
|
+
# HEADERS frames can be sent on a stream in the "idle", "reserved (local)", "open", or "half-closed (remote)" state. Despite it's name, it can also be used for trailers.
|
152
138
|
def send_headers?
|
153
139
|
@state == :idle or @state == :reserved_local or @state == :open or @state == :half_closed_remote
|
154
140
|
end
|
@@ -399,6 +385,8 @@ module Protocol
|
|
399
385
|
else
|
400
386
|
raise ProtocolError, "Cannot reserve stream in state: #{@state}"
|
401
387
|
end
|
388
|
+
|
389
|
+
return self
|
402
390
|
end
|
403
391
|
|
404
392
|
def reserved_remote!
|
@@ -407,6 +395,8 @@ module Protocol
|
|
407
395
|
else
|
408
396
|
raise ProtocolError, "Cannot reserve stream in state: #{@state}"
|
409
397
|
end
|
398
|
+
|
399
|
+
return self
|
410
400
|
end
|
411
401
|
|
412
402
|
# Override this function to implement your own push promise logic.
|
@@ -421,8 +411,10 @@ module Protocol
|
|
421
411
|
promised_stream = self.create_push_promise_stream(headers)
|
422
412
|
promised_stream.reserved_local!
|
423
413
|
|
414
|
+
# The headers are the same as if the client had sent a request:
|
424
415
|
write_push_promise(promised_stream.id, headers)
|
425
416
|
|
417
|
+
# The server should call send_headers on the promised stream to begin sending the response:
|
426
418
|
return promised_stream
|
427
419
|
else
|
428
420
|
raise ProtocolError, "Cannot send push promise in state: #{@state}"
|
@@ -448,10 +440,6 @@ module Protocol
|
|
448
440
|
def inspect
|
449
441
|
"\#<#{self.class} id=#{@id} state=#{@state}>"
|
450
442
|
end
|
451
|
-
|
452
|
-
def to_s
|
453
|
-
inspect
|
454
|
-
end
|
455
443
|
end
|
456
444
|
end
|
457
445
|
end
|
@@ -1,25 +1,10 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
20
5
|
|
21
6
|
module Protocol
|
22
7
|
module HTTP2
|
23
|
-
VERSION = "0.
|
8
|
+
VERSION = "0.15.0"
|
24
9
|
end
|
25
10
|
end
|
@@ -1,22 +1,7 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
20
5
|
|
21
6
|
require_relative 'frame'
|
22
7
|
|
@@ -44,6 +29,12 @@ module Protocol
|
|
44
29
|
# When the value of SETTINGS_INITIAL_WINDOW_SIZE changes, a receiver MUST adjust the size of all stream flow-control windows that it maintains by the difference between the new value and the old value.
|
45
30
|
def capacity= value
|
46
31
|
difference = value - @capacity
|
32
|
+
|
33
|
+
# An endpoint MUST treat a change to SETTINGS_INITIAL_WINDOW_SIZE that causes any flow-control window to exceed the maximum size as a connection error of type FLOW_CONTROL_ERROR.
|
34
|
+
if (@available + difference) > MAXIMUM_ALLOWED_WINDOW_SIZE
|
35
|
+
raise FlowControlError, "Changing window size by #{difference} caused overflow: #{@available + difference} > #{MAXIMUM_ALLOWED_WINDOW_SIZE}!"
|
36
|
+
end
|
37
|
+
|
47
38
|
@available += difference
|
48
39
|
@capacity = value
|
49
40
|
end
|
@@ -60,13 +51,15 @@ module Protocol
|
|
60
51
|
end
|
61
52
|
|
62
53
|
def expand(amount)
|
54
|
+
available = @available + amount
|
55
|
+
|
56
|
+
if available > MAXIMUM_ALLOWED_WINDOW_SIZE
|
57
|
+
raise FlowControlError, "Expanding window by #{amount} caused overflow: #{available} > #{MAXIMUM_ALLOWED_WINDOW_SIZE}!"
|
58
|
+
end
|
59
|
+
|
63
60
|
# puts "expand(#{amount}) @available=#{@available}"
|
64
61
|
@available += amount
|
65
62
|
@used -= amount
|
66
|
-
|
67
|
-
if @available > MAXIMUM_ALLOWED_WINDOW_SIZE
|
68
|
-
raise FlowControlError, "Expanding window by #{amount} caused overflow: #{@available} > #{MAXIMUM_ALLOWED_WINDOW_SIZE}!"
|
69
|
-
end
|
70
63
|
end
|
71
64
|
|
72
65
|
def wanted
|
@@ -77,8 +70,8 @@ module Protocol
|
|
77
70
|
@available < (@capacity / 2)
|
78
71
|
end
|
79
72
|
|
80
|
-
def
|
81
|
-
"
|
73
|
+
def inspect
|
74
|
+
"\#<#{self.class} used=#{@used} available=#{@available} capacity=#{@capacity}>"
|
82
75
|
end
|
83
76
|
end
|
84
77
|
|
@@ -102,7 +95,11 @@ module Protocol
|
|
102
95
|
end
|
103
96
|
|
104
97
|
def limited?
|
105
|
-
|
98
|
+
if @desired
|
99
|
+
@available < @desired
|
100
|
+
else
|
101
|
+
super
|
102
|
+
end
|
106
103
|
end
|
107
104
|
end
|
108
105
|
|
data/lib/protocol/http2.rb
CHANGED
@@ -1,22 +1,7 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
20
5
|
|
21
6
|
require_relative 'http2/version'
|
22
7
|
require_relative 'http2/connection'
|
data/license.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# MIT License
|
2
|
+
|
3
|
+
Copyright, 2019-2023, by Samuel Williams.
|
4
|
+
Copyright, 2019, by Yuta Iwama.
|
5
|
+
Copyright, 2020, by Olle Jonsson.
|
6
|
+
Copyright, 2023, by Marco Concetto Rudilosso.
|
7
|
+
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
10
|
+
in the Software without restriction, including without limitation the rights
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
13
|
+
furnished to do so, subject to the following conditions:
|
14
|
+
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
16
|
+
copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
24
|
+
SOFTWARE.
|
data/readme.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# Protocol::HTTP2
|
2
|
+
|
3
|
+
Provides a low-level implementation of the HTTP/2 protocol.
|
4
|
+
|
5
|
+
[![Development Status](https://github.com/socketry/protocol-http2/workflows/Test/badge.svg)](https://github.com/socketry/protocol-http2/actions?workflow=Test)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
``` ruby
|
12
|
+
gem 'protocol-http2'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install protocol-http2
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Here is a basic HTTP/2 client:
|
26
|
+
|
27
|
+
``` ruby
|
28
|
+
require 'async'
|
29
|
+
require 'async/io/stream'
|
30
|
+
require 'async/http/endpoint'
|
31
|
+
require 'protocol/http2/client'
|
32
|
+
|
33
|
+
Async do
|
34
|
+
endpoint = Async::HTTP::Endpoint.parse("https://www.google.com/search?q=kittens")
|
35
|
+
|
36
|
+
peer = endpoint.connect
|
37
|
+
|
38
|
+
puts "Connected to #{peer.inspect}"
|
39
|
+
|
40
|
+
# IO Buffering...
|
41
|
+
stream = Async::IO::Stream.new(peer)
|
42
|
+
|
43
|
+
framer = Protocol::HTTP2::Framer.new(stream)
|
44
|
+
client = Protocol::HTTP2::Client.new(framer)
|
45
|
+
|
46
|
+
puts "Sending connection preface..."
|
47
|
+
client.send_connection_preface
|
48
|
+
|
49
|
+
puts "Creating stream..."
|
50
|
+
stream = client.create_stream
|
51
|
+
|
52
|
+
headers = [
|
53
|
+
[":scheme", endpoint.scheme],
|
54
|
+
[":method", "GET"],
|
55
|
+
[":authority", "www.google.com"],
|
56
|
+
[":path", endpoint.path],
|
57
|
+
["accept", "*/*"],
|
58
|
+
]
|
59
|
+
|
60
|
+
puts "Sending request on stream id=#{stream.id} state=#{stream.state}..."
|
61
|
+
stream.send_headers(nil, headers, Protocol::HTTP2::END_STREAM)
|
62
|
+
|
63
|
+
puts "Waiting for response..."
|
64
|
+
$count = 0
|
65
|
+
|
66
|
+
def stream.process_headers(frame)
|
67
|
+
headers = super
|
68
|
+
puts "Got response headers: #{headers} (#{frame.end_stream?})"
|
69
|
+
end
|
70
|
+
|
71
|
+
def stream.receive_data(frame)
|
72
|
+
data = super
|
73
|
+
|
74
|
+
$count += data.scan(/kittens/).count
|
75
|
+
|
76
|
+
puts "Got response data: #{data.bytesize}"
|
77
|
+
end
|
78
|
+
|
79
|
+
until stream.closed?
|
80
|
+
frame = client.read_frame
|
81
|
+
end
|
82
|
+
|
83
|
+
puts "Got #{$count} kittens!"
|
84
|
+
|
85
|
+
puts "Closing client..."
|
86
|
+
client.close
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
We welcome contributions to this project.
|
93
|
+
|
94
|
+
1. Fork it.
|
95
|
+
2. Create your feature branch (`git checkout -b my-new-feature`).
|
96
|
+
3. Commit your changes (`git commit -am 'Add some feature'`).
|
97
|
+
4. Push to the branch (`git push origin my-new-feature`).
|
98
|
+
5. Create new Pull Request.
|
data.tar.gz.sig
ADDED