protocol-http1 0.25.0 → 0.27.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
- checksums.yaml.gz.sig +0 -0
- data/lib/protocol/http1/connection.rb +49 -26
- data/lib/protocol/http1/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88bedd2de9b6357ee48174d2a984d5f8cdc391311b0ac13cbd21c4e398d2076b
|
4
|
+
data.tar.gz: 4e631b85f63d21cd5dc4e93a49b014301d4faf42c8f0c04bc4341045a34cffe7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 751ca8414f97b9e6a35daf7350e6e5afb5d59bb3c6be1d740aa78c57a838111c49757b0da43f2875899b6b94d050fc0d163dd4a9d449f2f8450a6b219b7a07fc
|
7
|
+
data.tar.gz: 879adf7b92618c4707459c5498f1a8c5567a01c73c466c371f32488820f54b85b17ab92e1259434bf64d4e7b48dcc92d2a6e70eca273a90094ed87773a22c315
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -91,8 +91,8 @@ module Protocol
|
|
91
91
|
# │ ▼ └───┬────┘ ▼
|
92
92
|
# │ ┌──────────┐ │ ┌──────────┐
|
93
93
|
# │ │ half │ │ │ half │
|
94
|
-
# │ │ closed │ │
|
95
|
-
# │ │ (remote) │ │
|
94
|
+
# │ │ closed │ │ send R / │ closed │
|
95
|
+
# │ │ (remote) │ │ recv R │ (local) │
|
96
96
|
# │ └────┬─────┘ │ └─────┬────┘
|
97
97
|
# │ │ │ │
|
98
98
|
# │ │ send ES / │ recv ES / │
|
@@ -104,7 +104,8 @@ module Protocol
|
|
104
104
|
# persistent └────────┘
|
105
105
|
# ```
|
106
106
|
#
|
107
|
-
# - `ES`: the body was fully received or sent (end of stream)
|
107
|
+
# - `ES`: the body was fully received or sent (end of stream).
|
108
|
+
# - `R`: the connection was closed unexpectedly (reset).
|
108
109
|
#
|
109
110
|
# State transition methods use a trailing "!".
|
110
111
|
attr_accessor :state
|
@@ -176,14 +177,16 @@ module Protocol
|
|
176
177
|
# @return [IO] the underlying non-blocking IO.
|
177
178
|
def hijack!
|
178
179
|
@persistent = false
|
179
|
-
stream = @stream
|
180
180
|
|
181
|
-
@stream
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
181
|
+
if stream = @stream
|
182
|
+
@stream = nil
|
183
|
+
stream.flush
|
184
|
+
|
185
|
+
@state = :hijacked
|
186
|
+
self.closed
|
187
|
+
|
188
|
+
return stream
|
189
|
+
end
|
187
190
|
end
|
188
191
|
|
189
192
|
def close_read
|
@@ -193,16 +196,28 @@ module Protocol
|
|
193
196
|
end
|
194
197
|
|
195
198
|
# Close the connection and underlying stream.
|
196
|
-
def close
|
199
|
+
def close(error = nil)
|
197
200
|
@persistent = false
|
198
|
-
|
199
|
-
|
201
|
+
|
202
|
+
if stream = @stream
|
203
|
+
@stream = nil
|
204
|
+
stream.close
|
205
|
+
end
|
206
|
+
|
207
|
+
unless closed?
|
208
|
+
@state = :closed
|
209
|
+
self.closed(error)
|
210
|
+
end
|
200
211
|
end
|
201
212
|
|
202
213
|
def open!
|
203
|
-
|
214
|
+
unless @state == :idle
|
215
|
+
raise ProtocolError, "Cannot open connection in state: #{@state}!"
|
216
|
+
end
|
204
217
|
|
205
218
|
@state = :open
|
219
|
+
|
220
|
+
return self
|
206
221
|
end
|
207
222
|
|
208
223
|
def write_request(authority, method, path, version, headers)
|
@@ -216,7 +231,7 @@ module Protocol
|
|
216
231
|
|
217
232
|
def write_response(version, status, headers, reason = Reason::DESCRIPTIONS[status])
|
218
233
|
unless @state == :open or @state == :half_closed_remote
|
219
|
-
raise ProtocolError, "Cannot write response in #{@state}!"
|
234
|
+
raise ProtocolError, "Cannot write response in state: #{@state}!"
|
220
235
|
end
|
221
236
|
|
222
237
|
# Safari WebSockets break if no reason is given:
|
@@ -227,7 +242,7 @@ module Protocol
|
|
227
242
|
|
228
243
|
def write_interim_response(version, status, headers, reason = Reason::DESCRIPTIONS[status])
|
229
244
|
unless @state == :open or @state == :half_closed_remote
|
230
|
-
raise ProtocolError, "Cannot write interim response in #{@state}!"
|
245
|
+
raise ProtocolError, "Cannot write interim response in state: #{@state}!"
|
231
246
|
end
|
232
247
|
|
233
248
|
@stream.write("#{version} #{status} #{reason}\r\n")
|
@@ -321,7 +336,7 @@ module Protocol
|
|
321
336
|
|
322
337
|
def read_response(method)
|
323
338
|
unless @state == :open or @state == :half_closed_local
|
324
|
-
raise ProtocolError, "Cannot read response in #{@state}!"
|
339
|
+
raise ProtocolError, "Cannot read response in state: #{@state}!"
|
325
340
|
end
|
326
341
|
|
327
342
|
version, status, reason = read_response_line
|
@@ -364,9 +379,9 @@ module Protocol
|
|
364
379
|
if @state == :open
|
365
380
|
@state = :half_closed_local
|
366
381
|
elsif @state == :half_closed_remote
|
367
|
-
self.
|
382
|
+
self.close!
|
368
383
|
else
|
369
|
-
raise ProtocolError, "Cannot send end stream in #{@state}!"
|
384
|
+
raise ProtocolError, "Cannot send end stream in state: #{@state}!"
|
370
385
|
end
|
371
386
|
end
|
372
387
|
|
@@ -518,16 +533,24 @@ module Protocol
|
|
518
533
|
self.send_end_stream!
|
519
534
|
end
|
520
535
|
|
521
|
-
|
522
|
-
|
536
|
+
# The connection (stream) was closed. It may now be in the idle state.
|
537
|
+
def closed(error = nil)
|
523
538
|
end
|
524
539
|
|
525
|
-
|
526
|
-
|
527
|
-
|
540
|
+
# Transition to the closed state.
|
541
|
+
#
|
542
|
+
# If no error occurred, and the connection is persistent, this will immediately transition to the idle state.
|
543
|
+
#
|
544
|
+
# @parameter error [Exxception] the error that caused the connection to close.
|
545
|
+
def close!(error = nil)
|
546
|
+
if @persistent and !error
|
547
|
+
# If there was no error, and the connection is persistent, we can reuse it:
|
548
|
+
@state = :idle
|
528
549
|
else
|
529
550
|
@state = :closed
|
530
551
|
end
|
552
|
+
|
553
|
+
self.closed(error)
|
531
554
|
end
|
532
555
|
|
533
556
|
def write_body(version, body, head = false, trailer = nil)
|
@@ -565,9 +588,9 @@ module Protocol
|
|
565
588
|
if @state == :open
|
566
589
|
@state = :half_closed_remote
|
567
590
|
elsif @state == :half_closed_local
|
568
|
-
self.
|
591
|
+
self.close!
|
569
592
|
else
|
570
|
-
raise ProtocolError, "Cannot receive end stream in #{@state}!"
|
593
|
+
raise ProtocolError, "Cannot receive end stream in state: #{@state}!"
|
571
594
|
end
|
572
595
|
end
|
573
596
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protocol-http1
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.27.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -42,7 +42,7 @@ cert_chain:
|
|
42
42
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
43
43
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
44
44
|
-----END CERTIFICATE-----
|
45
|
-
date: 2024-09-
|
45
|
+
date: 2024-09-24 00:00:00.000000000 Z
|
46
46
|
dependencies:
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: protocol-http
|
metadata.gz.sig
CHANGED
Binary file
|