protocol-http2 0.1.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.
@@ -0,0 +1,104 @@
1
+ # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
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.
20
+
21
+ require_relative 'frame'
22
+
23
+ module Protocol
24
+ module HTTP2
25
+ class Window
26
+ # @param capacity [Integer] The initial window size, typically from the settings.
27
+ def initialize(capacity = 0xFFFF)
28
+ # This is the main field required:
29
+ @available = capacity
30
+
31
+ # These two fields are primarily used for efficiently sending window updates:
32
+ @used = 0
33
+ @capacity = capacity
34
+
35
+ fail unless capacity
36
+ end
37
+
38
+ def dup
39
+ return self.class.new(@capacity)
40
+ end
41
+
42
+ # The window is completely full?
43
+ def full?
44
+ @available.zero?
45
+ end
46
+
47
+ attr :used
48
+ attr :capacity
49
+
50
+ # 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.
51
+ def capacity= value
52
+ difference = value - @capacity
53
+ @available += difference
54
+ end
55
+
56
+ def consume(amount)
57
+ @available -= amount
58
+ @used += amount
59
+ end
60
+
61
+ attr :available
62
+
63
+ def available?
64
+ @available > 0
65
+ end
66
+
67
+ def expand(amount)
68
+ @available += amount
69
+ @used -= amount
70
+ end
71
+
72
+ def limited?
73
+ @available < (@capacity / 2)
74
+ end
75
+
76
+ def to_s
77
+ "\#<Window used=#{@used} available=#{@available} capacity=#{@capacity}>"
78
+ end
79
+ end
80
+
81
+ # The WINDOW_UPDATE frame is used to implement flow control.
82
+ #
83
+ # +-+-------------------------------------------------------------+
84
+ # |R| Window Size Increment (31) |
85
+ # +-+-------------------------------------------------------------+
86
+ #
87
+ class WindowUpdateFrame < Frame
88
+ TYPE = 0x8
89
+ FORMAT = "N"
90
+
91
+ def pack(window_size_increment)
92
+ super [window_size_increment].pack(FORMAT)
93
+ end
94
+
95
+ def unpack
96
+ super.unpack(FORMAT).first
97
+ end
98
+
99
+ def apply(connection)
100
+ connection.receive_window_update(self)
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,22 @@
1
+ # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
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.
20
+
21
+ require_relative 'http2/version'
22
+ require_relative 'http2/connection'
@@ -0,0 +1,28 @@
1
+
2
+ require_relative "lib/protocol/http2/version"
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "protocol-http2"
6
+ spec.version = Protocol::HTTP2::VERSION
7
+ spec.authors = ["Samuel Williams"]
8
+ spec.email = ["samuel.williams@oriontransfer.co.nz"]
9
+
10
+ spec.summary = "A low level implementation of the HTTP/2 protocol."
11
+ spec.homepage = "https://github.com/socketry/protocol-http2"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
15
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ end
17
+
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "protocol-hpack", "~> 1.0"
22
+ spec.add_dependency "protocol-http"
23
+
24
+ spec.add_development_dependency "covered"
25
+ spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: protocol-http2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: protocol-hpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: protocol-http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: covered
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description:
98
+ email:
99
+ - samuel.williams@oriontransfer.co.nz
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - README.md
109
+ - Rakefile
110
+ - examples/http2/request.rb
111
+ - examples/http2/requests.rb
112
+ - lib/protocol/http2.rb
113
+ - lib/protocol/http2/client.rb
114
+ - lib/protocol/http2/connection.rb
115
+ - lib/protocol/http2/continuation_frame.rb
116
+ - lib/protocol/http2/data_frame.rb
117
+ - lib/protocol/http2/error.rb
118
+ - lib/protocol/http2/flow_control.rb
119
+ - lib/protocol/http2/frame.rb
120
+ - lib/protocol/http2/framer.rb
121
+ - lib/protocol/http2/goaway_frame.rb
122
+ - lib/protocol/http2/headers_frame.rb
123
+ - lib/protocol/http2/padded.rb
124
+ - lib/protocol/http2/ping_frame.rb
125
+ - lib/protocol/http2/priority_frame.rb
126
+ - lib/protocol/http2/push_promise_frame.rb
127
+ - lib/protocol/http2/reset_stream_frame.rb
128
+ - lib/protocol/http2/server.rb
129
+ - lib/protocol/http2/settings_frame.rb
130
+ - lib/protocol/http2/stream.rb
131
+ - lib/protocol/http2/version.rb
132
+ - lib/protocol/http2/window_update_frame.rb
133
+ - protocol-http2.gemspec
134
+ homepage: https://github.com/socketry/protocol-http2
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubygems_version: 3.0.2
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: A low level implementation of the HTTP/2 protocol.
157
+ test_files: []