protocol-http1 0.24.0 → 0.25.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: '0854252b3602c1271818e28024b62e1a4373521052b75ba0aa879a1f77a6e84e'
4
- data.tar.gz: 2ad1603fc177c4b8493f304806a1f8baf4dc147b0f1707d463f534fb1e740a62
3
+ metadata.gz: ad917a8e0aa2f76df0ea21a56a914dc6575d1e22ee13a2b36a60f5a1ca37ed6e
4
+ data.tar.gz: 2d6adbe2df3cd0c712e381a46adbba85de481ece8ee77ada0cf9a8b0638fc35a
5
5
  SHA512:
6
- metadata.gz: 213525d129854f2198cb1be6be3d99a74d7add2e4a8dc57ed72d3bd1854b29535256120dfcbd735f1823d91bb6bf27fee6571d93d8e85f0031a404be99b39e01
7
- data.tar.gz: 32f7a63f81f830a77839fa154b69bfa5a8dc316d579cc48e10d2a786e92806960c36821b3f53da67c3b1e90ba29394264ae76c621d7608c62a0d56224dabec1f
6
+ metadata.gz: 5f9b082e5bf6756d18127ad03ba0a2b14568227f859c05d7391983ce2a1157241cf635dcb3bc865264dfb6fb639991650c30b5ad2a8bb56ba1177ee11bce8a05
7
+ data.tar.gz: a050ed9a0618856e61cfdc8d2e45a268ace98bb97ce6a76ba384480db55abc7fb7c71d113c967b1dfa9e53f5ce56c4469a7559f9eddb41a51c06b168a8b85b7b
checksums.yaml.gz.sig CHANGED
Binary file
@@ -22,23 +22,27 @@ module Protocol
22
22
  @count = 0
23
23
  end
24
24
 
25
+ attr :count
26
+
27
+ def length
28
+ # We only know the length once we've read everything. This is because the length is not known until the final chunk is read.
29
+ if @finished
30
+ @length
31
+ end
32
+ end
33
+
25
34
  def empty?
26
35
  @connection.nil?
27
36
  end
28
37
 
29
- def discard
38
+ def close(error = nil)
30
39
  if connection = @connection
31
40
  @connection = nil
32
41
 
33
- # We only close the connection if we haven't completed reading the entire body:
34
42
  unless @finished
35
43
  connection.close_read
36
44
  end
37
45
  end
38
- end
39
-
40
- def close(error = nil)
41
- self.discard
42
46
 
43
47
  super
44
48
  end
@@ -82,7 +86,8 @@ module Protocol
82
86
  return chunk
83
87
  else
84
88
  # The connection has been closed before we have read the requested length:
85
- self.discard
89
+ @connection.close_read
90
+ @connection = nil
86
91
  end
87
92
  end
88
93
 
@@ -23,18 +23,14 @@ module Protocol
23
23
  @connection.nil? or @remaining == 0
24
24
  end
25
25
 
26
- def discard
26
+ def close(error = nil)
27
27
  if connection = @connection
28
28
  @connection = nil
29
29
 
30
- if @remaining != 0
30
+ unless @remaining == 0
31
31
  connection.close_read
32
32
  end
33
33
  end
34
- end
35
-
36
- def close(error = nil)
37
- self.discard
38
34
 
39
35
  super
40
36
  end
@@ -39,8 +39,12 @@ module Protocol
39
39
  def read
40
40
  @connection&.readpartial(BLOCK_SIZE)
41
41
  rescue EOFError
42
- @connection.receive_end_stream!
43
- @connection = nil
42
+ if connection = @connection
43
+ @connection = nil
44
+ connection.receive_end_stream!
45
+ end
46
+
47
+ return nil
44
48
  end
45
49
 
46
50
  def inspect
@@ -181,12 +181,22 @@ module Protocol
181
181
  @stream.flush
182
182
  @stream = nil
183
183
 
184
+ self.closed!
185
+
184
186
  return stream
185
187
  end
186
188
 
189
+ def close_read
190
+ @persistent = false
191
+ @stream&.close_read
192
+ self.receive_end_stream!
193
+ end
194
+
187
195
  # Close the connection and underlying stream.
188
196
  def close
197
+ @persistent = false
189
198
  @stream&.close
199
+ self.closed!
190
200
  end
191
201
 
192
202
  def open!
@@ -264,10 +274,6 @@ module Protocol
264
274
  read_line? or raise EOFError
265
275
  end
266
276
 
267
- def close_read
268
- @stream.close_read
269
- end
270
-
271
277
  def read_request_line
272
278
  return unless line = read_line?
273
279
 
@@ -354,6 +360,16 @@ module Protocol
354
360
  return HTTP::Headers.new(fields)
355
361
  end
356
362
 
363
+ def send_end_stream!
364
+ if @state == :open
365
+ @state = :half_closed_local
366
+ elsif @state == :half_closed_remote
367
+ self.closed!
368
+ else
369
+ raise ProtocolError, "Cannot send end stream in #{@state}!"
370
+ end
371
+ end
372
+
357
373
  # @param protocol [String] the protocol to upgrade to.
358
374
  def write_upgrade_body(protocol, body = nil)
359
375
  # Once we upgrade the connection, it can no longer handle other requests:
@@ -374,6 +390,8 @@ module Protocol
374
390
  end
375
391
 
376
392
  return @stream
393
+ ensure
394
+ self.send_end_stream!
377
395
  end
378
396
 
379
397
  def write_tunnel_body(version, body = nil)
@@ -394,6 +412,8 @@ module Protocol
394
412
  end
395
413
 
396
414
  return @stream
415
+ ensure
416
+ self.send_end_stream!
397
417
  end
398
418
 
399
419
  def write_empty_body(body)
@@ -401,6 +421,8 @@ module Protocol
401
421
  @stream.flush
402
422
 
403
423
  body&.close
424
+ ensure
425
+ self.send_end_stream!
404
426
  end
405
427
 
406
428
  def write_fixed_length_body(body, length, head)
@@ -433,6 +455,8 @@ module Protocol
433
455
  if chunk_length != length
434
456
  raise ContentLengthError, "Wrote #{chunk_length} bytes, but content length was #{length} bytes!"
435
457
  end
458
+ ensure
459
+ self.send_end_stream!
436
460
  end
437
461
 
438
462
  def write_chunked_body(body, head, trailer = nil)
@@ -467,6 +491,8 @@ module Protocol
467
491
  end
468
492
 
469
493
  @stream.flush
494
+ ensure
495
+ self.send_end_stream!
470
496
  end
471
497
 
472
498
  def write_body_and_close(body, head)
@@ -488,6 +514,8 @@ module Protocol
488
514
 
489
515
  @stream.flush
490
516
  @stream.close_write
517
+ ensure
518
+ self.send_end_stream!
491
519
  end
492
520
 
493
521
  def idle!
@@ -495,10 +523,6 @@ module Protocol
495
523
  end
496
524
 
497
525
  def closed!
498
- unless @state == :half_closed_local or @state == :half_closed_remote
499
- raise ProtocolError, "Cannot close in #{@state}!"
500
- end
501
-
502
526
  if @persistent
503
527
  self.idle!
504
528
  else
@@ -506,16 +530,6 @@ module Protocol
506
530
  end
507
531
  end
508
532
 
509
- def send_end_stream!
510
- if @state == :open
511
- @state = :half_closed_local
512
- elsif @state == :half_closed_remote
513
- self.closed!
514
- else
515
- raise ProtocolError, "Cannot send end stream in #{@state}!"
516
- end
517
- end
518
-
519
533
  def write_body(version, body, head = false, trailer = nil)
520
534
  # HTTP/1.0 cannot in any case handle trailers.
521
535
  if version == HTTP10 # or te: trailers was not present (strictly speaking not required.)
@@ -545,8 +559,6 @@ module Protocol
545
559
  write_connection_header(version)
546
560
  write_body_and_close(body, head)
547
561
  end
548
- ensure
549
- send_end_stream!
550
562
  end
551
563
 
552
564
  def receive_end_stream!
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module HTTP1
8
- VERSION = "0.24.0"
8
+ VERSION = "0.25.0"
9
9
  end
10
10
  end
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.24.0
4
+ version: 0.25.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-18 00:00:00.000000000 Z
45
+ date: 2024-09-19 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