protocol-http 0.28.1 → 0.29.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/http/body/buffered.rb +21 -11
- data/lib/protocol/http/body/completable.rb +8 -0
- data/lib/protocol/http/body/readable.rb +9 -1
- data/lib/protocol/http/body/rewindable.rb +17 -1
- data/lib/protocol/http/body/stream.rb +18 -5
- data/lib/protocol/http/body/wrapper.rb +12 -0
- data/lib/protocol/http/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: e5839d2adb8415083224423beb2d5a3c0a50e22090a75424276e1a0939cc800a
|
4
|
+
data.tar.gz: 0517ecffe3b1f6c486b1cba2b5cbf4b3b7a8daf2cb11469b73d0d61cb5492cb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
#
|
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(
|
21
|
-
if
|
22
|
-
return
|
23
|
-
elsif
|
24
|
-
return self.new(
|
25
|
-
elsif
|
26
|
-
return self.new([
|
27
|
-
elsif
|
28
|
-
return self.
|
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
|
-
|
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
|
@@ -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.
|
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
|
@@ -89,12 +89,25 @@ module Protocol
|
|
89
89
|
# Will avoid reading from the underlying stream if there is buffered data available.
|
90
90
|
#
|
91
91
|
# @parameter length [Integer] The maximum number of bytes to read.
|
92
|
-
def read_partial(length = nil)
|
92
|
+
def read_partial(length = nil, buffer = nil)
|
93
93
|
if @buffer
|
94
|
-
|
94
|
+
if buffer
|
95
|
+
buffer.replace(@buffer)
|
96
|
+
else
|
97
|
+
buffer = @buffer
|
98
|
+
end
|
95
99
|
@buffer = nil
|
96
100
|
else
|
97
|
-
|
101
|
+
if chunk = read_next
|
102
|
+
if buffer
|
103
|
+
buffer.replace(chunk)
|
104
|
+
else
|
105
|
+
buffer = chunk
|
106
|
+
end
|
107
|
+
else
|
108
|
+
buffer&.clear
|
109
|
+
buffer = nil
|
110
|
+
end
|
98
111
|
end
|
99
112
|
|
100
113
|
if buffer and length
|
@@ -111,8 +124,8 @@ module Protocol
|
|
111
124
|
end
|
112
125
|
|
113
126
|
# Similar to {read_partial} but raises an `EOFError` if the stream is at EOF.
|
114
|
-
def readpartial(length)
|
115
|
-
read_partial(length) or raise EOFError, "End of file reached!"
|
127
|
+
def readpartial(length, buffer = nil)
|
128
|
+
read_partial(length, buffer) or raise EOFError, "End of file reached!"
|
116
129
|
end
|
117
130
|
|
118
131
|
# Read data from the stream without blocking if possible.
|
@@ -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
|
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.
|
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-
|
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
|