protocol-http2 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74d3097dff56a20525423ad77d0f561d3c7571488dcb4c0eaa8714f6ac6a29ff
4
- data.tar.gz: 795f564f2af3927fde4c0c0f76e04ba785d5b0056eb11978e883d3a0553bdaca
3
+ metadata.gz: 1a60f785211de9969cb282720013a13d2586d07b740ef1c7d944dab9da6dfd47
4
+ data.tar.gz: 27698d4cbbedb0aa3fea412962c36dc72f081d0c3e494bfaffc5beaa37d17806
5
5
  SHA512:
6
- metadata.gz: eb8fe96eb3bdc7c3f8ba8b2185e2dba35af613985120ecb23b2750def0a3bc49ab62170b79c94b36f03856904df29effdc8f7250d5dee446e81062f9d8f9d610
7
- data.tar.gz: 1904ab5ef55fb6ae3f327fc7305197cd809d11c6ea7992281d1e0035d987390fe07cb290fceb57107f094380c7553036d59a690803b9bb2f1a7bbc7a66de9fb1
6
+ metadata.gz: 525676f325a064c8e060352d8e865c99a7353a271fd44893ad7aa645f132cffb9e83b40d80c6e430496f517f7f777c3dac5dd666db343e14b3845b623065a375
7
+ data.tar.gz: d7da9b3249e5547f18378f2bb4fc060385d49469f5759af7dd775280567fa89334cd04b8c805573ec522ad7a4225fbd5ae683d9a685a4f1829af2d66cc317f31
@@ -149,6 +149,12 @@ module Protocol
149
149
 
150
150
  def receive_goaway(frame)
151
151
  @state = :closed
152
+
153
+ last_stream_id, error_code, message = frame.unpack
154
+
155
+ if error_code != 0
156
+ raise GoawayError.new message, error_code
157
+ end
152
158
  end
153
159
 
154
160
  def write_frame(frame)
@@ -22,15 +22,85 @@ require 'protocol/http/error'
22
22
 
23
23
  module Protocol
24
24
  module HTTP2
25
- class ProtocolError < HTTP::ProtocolError
25
+ # Status codes as defined by <https://tools.ietf.org/html/rfc7540#section-7>.
26
+ class Error < HTTP::Error
27
+ # The associated condition is not a result of an error. For example, a GOAWAY might include this code to indicate graceful shutdown of a connection.
28
+ NO_ERROR = 0x0
29
+
30
+ # The endpoint detected an unspecific protocol error. This error is for use when a more specific error code is not available.
31
+ PROTOCOL_ERROR = 0x1
32
+
33
+ # The endpoint encountered an unexpected internal error.
34
+ INTERNAL_ERROR = 0x2
35
+
36
+ # The endpoint detected that its peer violated the flow-control protocol.
37
+ FLOW_CONTROL_ERROR = 0x3
38
+
39
+ # The endpoint sent a SETTINGS frame but did not receive a response in a timely manner.
40
+ SETTINGS_TIMEOUT = 0x4
41
+
42
+ # The endpoint received a frame after a stream was half-closed.
43
+ STREAM_CLOSED = 0x5
44
+
45
+ # The endpoint received a frame with an invalid size.
46
+ FRAME_SIZE_ERROR = 0x6
47
+
48
+ # The endpoint refused the stream prior to performing any application processing.
49
+ REFUSED_STREAM = 0x7
50
+
51
+ # Used by the endpoint to indicate that the stream is no longer needed.
52
+ CANCEL = 0x8
53
+
54
+ # The endpoint is unable to maintain the header compression context for the connection.
55
+ COMPRESSION_ERROR = 0x9
56
+
57
+ # The connection established in response to a CONNECT request was reset or abnormally closed.
58
+ CONNECT_ERROR = 0xA
59
+
60
+ # The endpoint detected that its peer is exhibiting a behavior that might be generating excessive load.
61
+ ENHANCE_YOUR_CALM = 0xB
62
+
63
+ # The underlying transport has properties that do not meet minimum security requirements.
64
+ INADEQUATE_SECURITY = 0xC
65
+
66
+ # The endpoint requires that HTTP/1.1 be used instead of HTTP/2.
67
+ HTTP_1_1_REQUIRED = 0xD
68
+ end
69
+
70
+ # Raised if connection header is missing or invalid indicating that
71
+ # this is an invalid HTTP 2.0 request - no frames are emitted and the
72
+ # connection must be aborted.
73
+ class HandshakeError < Error
74
+ end
75
+
76
+ # Raised by stream or connection handlers, results in GOAWAY frame
77
+ # which signals termination of the current connection. You *cannot*
78
+ # recover from this exception, or any exceptions subclassed from it.
79
+ class ProtocolError < Error
80
+ def initialize(message, code = PROTOCOL_ERROR)
81
+ super(message)
82
+
83
+ @code = code
84
+ end
85
+
86
+ attr :code
87
+ end
88
+
89
+ class GoawayError < ProtocolError
26
90
  end
27
91
 
28
92
  # When the frame payload does not match expectations.
29
93
  class FrameSizeError < ProtocolError
94
+ def initialize(message)
95
+ super message, FRAME_SIZE_ERROR
96
+ end
30
97
  end
31
98
 
32
99
  # Raised on invalid flow control frame or command.
33
100
  class FlowControlError < ProtocolError
101
+ def initialize(message)
102
+ super message, FLOW_CONTROL_ERROR
103
+ end
34
104
  end
35
105
  end
36
106
  end
@@ -69,7 +69,7 @@ module Protocol
69
69
  string = @stream.read(CONNECTION_PREFACE_MAGIC.bytesize)
70
70
 
71
71
  unless string == CONNECTION_PREFACE_MAGIC
72
- raise ProtocolError, "Invalid connection preface: #{string.inspect}"
72
+ raise HandshakeError, "Invalid connection preface: #{string.inspect}"
73
73
  end
74
74
 
75
75
  return string
@@ -58,6 +58,7 @@ module Protocol
58
58
  if value <= MAXIMUM_ALLOWED_WINDOW_SIZE
59
59
  @initial_window_size = value
60
60
  else
61
+ # 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.
61
62
  raise FlowControlError, "Invalid value for initial_window_size: #{value} > #{MAXIMUM_ALLOWED_WINDOW_SIZE}"
62
63
  end
63
64
  end
@@ -158,7 +159,7 @@ module Protocol
158
159
 
159
160
  return changes
160
161
  else
161
- raise ProtocolError.new("Cannot acknowledge settings, no changes pending")
162
+ raise ProtocolError, "Cannot acknowledge settings, no changes pending"
162
163
  end
163
164
  end
164
165
 
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Protocol
22
22
  module HTTP2
23
- VERSION = "0.1.1"
23
+ VERSION = "0.2.0"
24
24
  end
25
25
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "protocol-hpack", "~> 1.0"
22
- spec.add_dependency "protocol-http"
22
+ spec.add_dependency "protocol-http", "~> 0.2"
23
23
 
24
24
  spec.add_development_dependency "covered"
25
25
  spec.add_development_dependency "bundler"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-http2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: protocol-http
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '0.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '0.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: covered
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
152
  requirements: []
153
- rubygems_version: 3.0.3
153
+ rubygems_version: 3.0.2
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: A low level implementation of the HTTP/2 protocol.