protocol-http 0.28.2 → 0.29.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3bf15de4010337ee2c56c39bf6955ccfc7e6ae623426e31bface95cf15c8ef26
4
- data.tar.gz: f8d4d30147c5402ca5003195b5b2d6e1688b47bf1a56ee23131b420952efac68
3
+ metadata.gz: e5839d2adb8415083224423beb2d5a3c0a50e22090a75424276e1a0939cc800a
4
+ data.tar.gz: 0517ecffe3b1f6c486b1cba2b5cbf4b3b7a8daf2cb11469b73d0d61cb5492cb1
5
5
  SHA512:
6
- metadata.gz: 236c830db8716243e3c9d7eec818c4b6a6b83ab399efe131b3475a4a1aac9e57dbe7ad809d7e0b5f4715c40371c8b2adbd7ebb6c16571ef5397fc209f08244d8
7
- data.tar.gz: 35574f913cbaaee7f8ce06f8855843dd517f9d29ed898852c53c2ef12003fa0c62308ecd4e4dc3d04a7d34b4171ce64bb87b8d09779cfa69533f0da1c74b1be8
6
+ metadata.gz: 5fe865bc6ae53bfbd34ca9e43c6c38d2dcb3874b0655b1960936960b690cfefc0203ecde64ea7ea3af17a8a1093382d98f419e5d88b24708af99ef210a282e7e
7
+ data.tar.gz: 5c576ba8d79c0c6d21022d224b936f307640e2a785685cb82ec2eb0da588fcc8cbb215d2b7a05572ab91274978acc1f3a39edc0dfb5946fbef32dafa51389296
checksums.yaml.gz.sig CHANGED
Binary file
@@ -11,25 +11,29 @@ module Protocol
11
11
  module Body
12
12
  # A body which buffers all it's contents.
13
13
  class Buffered < Readable
14
- # Wraps an array into a buffered body.
14
+ # Tries to wrap an object in a {Buffered} instance.
15
15
  #
16
16
  # For compatibility, also accepts anything that behaves like an `Array(String)`.
17
17
  #
18
18
  # @parameter body [String | Array(String) | Readable | nil] the body to wrap.
19
19
  # @returns [Readable | nil] the wrapped body or nil if nil was given.
20
- def self.wrap(body)
21
- if body.is_a?(Readable)
22
- return body
23
- elsif body.is_a?(Array)
24
- return self.new(body)
25
- elsif body.is_a?(String)
26
- return self.new([body])
27
- elsif body
28
- return self.for(body)
20
+ def self.wrap(object)
21
+ if object.is_a?(Readable)
22
+ return object
23
+ elsif object.is_a?(Array)
24
+ return self.new(object)
25
+ elsif object.is_a?(String)
26
+ return self.new([object])
27
+ elsif object
28
+ return self.read(object)
29
29
  end
30
30
  end
31
31
 
32
- def self.for(body)
32
+ # Read the entire body into a buffered representation.
33
+ #
34
+ # @parameter body [Readable] the body to read.
35
+ # @returns [Buffered] the buffered body.
36
+ def self.read(body)
33
37
  chunks = []
34
38
 
35
39
  body.each do |chunk|
@@ -77,8 +81,14 @@ module Protocol
77
81
  @chunks << chunk
78
82
  end
79
83
 
84
+ def rewindable?
85
+ true
86
+ end
87
+
80
88
  def rewind
81
89
  @index = 0
90
+
91
+ return true
82
92
  end
83
93
 
84
94
  def inspect
@@ -24,6 +24,14 @@ module Protocol
24
24
  @callback = callback
25
25
  end
26
26
 
27
+ def rewindable?
28
+ false
29
+ end
30
+
31
+ def rewind
32
+ false
33
+ end
34
+
27
35
  def finish
28
36
  super.tap do
29
37
  if @callback
@@ -29,6 +29,14 @@ module Protocol
29
29
  false
30
30
  end
31
31
 
32
+ def rewindable?
33
+ false
34
+ end
35
+
36
+ def rewind
37
+ false
38
+ end
39
+
32
40
  def length
33
41
  nil
34
42
  end
@@ -58,7 +66,7 @@ module Protocol
58
66
  # @returns [Buffered] The buffered body.
59
67
  def finish
60
68
  # Internally, this invokes `self.each` which then invokes `self.close`.
61
- Buffered.for(self)
69
+ Buffered.read(self)
62
70
  end
63
71
 
64
72
  # Enumerate all chunks until finished, then invoke `#close`.
@@ -11,6 +11,16 @@ module Protocol
11
11
  module Body
12
12
  # A body which buffers all it's contents as it is `#read`.
13
13
  class Rewindable < Wrapper
14
+ def self.wrap(message)
15
+ if body = message.body
16
+ if body.rewindable?
17
+ body
18
+ else
19
+ message.body = self.new(body)
20
+ end
21
+ end
22
+ end
23
+
14
24
  def initialize(body)
15
25
  super(body)
16
26
 
@@ -26,7 +36,9 @@ module Protocol
26
36
  (@index < @chunks.size) || super
27
37
  end
28
38
 
29
- # A rewindable body wraps some other body. Convert it to a buffered body
39
+ # A rewindable body wraps some other body. Convert it to a buffered body. The buffered body will share the same chunks as the rewindable body.
40
+ #
41
+ # @returns [Buffered] the buffered body.
30
42
  def buffered
31
43
  Buffered.new(@chunks)
32
44
  end
@@ -54,6 +66,10 @@ module Protocol
54
66
  @index = 0
55
67
  end
56
68
 
69
+ def rewindable?
70
+ true
71
+ end
72
+
57
73
  def inspect
58
74
  "\#<#{self.class} #{@index}/#{@chunks.size} chunks read>"
59
75
  end
@@ -10,6 +10,10 @@ module Protocol
10
10
  module Body
11
11
  # Wrapping body instance. Typically you'd override `#read`.
12
12
  class Wrapper < Readable
13
+ # Wrap the body of the given message in a new instance of this class.
14
+ #
15
+ # @parameter message [Request | Response] the message to wrap.
16
+ # @returns [Wrapper | nil] the wrapped body or nil if the body was nil.
13
17
  def self.wrap(message)
14
18
  if body = message.body
15
19
  message.body = self.new(body)
@@ -42,6 +46,14 @@ module Protocol
42
46
  @body.ready?
43
47
  end
44
48
 
49
+ def rewind
50
+ @body.rewind
51
+ end
52
+
53
+ def rewindable?
54
+ @body.rewindable?
55
+ end
56
+
45
57
  def length
46
58
  @body.length
47
59
  end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module HTTP
8
- VERSION = "0.28.2"
8
+ VERSION = "0.29.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-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.28.2
4
+ version: 0.29.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -47,7 +47,7 @@ cert_chain:
47
47
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
48
48
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
49
49
  -----END CERTIFICATE-----
50
- date: 2024-08-21 00:00:00.000000000 Z
50
+ date: 2024-08-28 00:00:00.000000000 Z
51
51
  dependencies: []
52
52
  description:
53
53
  email:
metadata.gz.sig CHANGED
Binary file