protocol-http 0.22.6 → 0.23.1

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: a2d1f5f6a59c2a1971e7d5e6ff1fdcfe73b67ad5046e5404e5daa30e40e39d83
4
- data.tar.gz: aad5c5263c1086a6164412549f5d549a101b8871453770bcb4e7dc4f34f24044
3
+ metadata.gz: ee01a36222c1035b06230948ac4afd7d5f8894416c7db3f46f3d2ff3735c84c4
4
+ data.tar.gz: 809f145dc27bdd25d8d39467b7583a1778c21e0f91d93e5bc5e697324b1e9d29
5
5
  SHA512:
6
- metadata.gz: f0ed818d3d25dfba4cbbe6f44d5255b711aa657d3c3b85889d88e807a6fc551488c075bb0257f3c3f87e8855fa4389132bf1a931e0b7b8d3e38382fe48bcd732
7
- data.tar.gz: 8a715d2bcd6b33c07f03b05bef621a87b75796c32d0a7aec9076125db3cdfb0c580513c6b7b4844fd0696fcaf0eb8f1df0f4542e23e4ea781cbcf140999530fb
6
+ metadata.gz: 4188214bf6e420e204a689484d2469e0d577270541a803bf366ceafa5fd8edcd652649a59616ce1b965744017785e348ea4a8ecdb396324af1c0815c423715da
7
+ data.tar.gz: 3450d3826c351d7e4da8a94bc4f6d9dac81fd8386a7c2eac4753077da0055344e924d7283090cc1f443261060dec0c0a1d5803f851e1690df3dc1405552a05b6
checksums.yaml.gz.sig ADDED
Binary file
@@ -72,7 +72,7 @@ module Protocol
72
72
  stream.write(chunk)
73
73
  end
74
74
  ensure
75
- stream.close($!)
75
+ stream.close
76
76
  end
77
77
 
78
78
  # Read all remaining chunks into a buffered body and close the underlying input.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
-
2
+ #
3
3
  # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -20,15 +20,19 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
+ require_relative 'buffered'
24
+
23
25
  module Protocol
24
26
  module HTTP
25
27
  module Body
26
28
  # The input stream is an IO-like object which contains the raw HTTP POST data. When applicable, its external encoding must be “ASCII-8BIT” and it must be opened in binary mode, for Ruby 1.9 compatibility. The input stream must respond to gets, each, read and rewind.
27
29
  class Stream
28
- def initialize(input, output)
30
+ def initialize(input, output = Buffered.new)
29
31
  @input = input
30
32
  @output = output
31
33
 
34
+ raise ArgumentError, "Non-writable output!" unless output.respond_to?(:write)
35
+
32
36
  # Will hold remaining data in `#read`.
33
37
  @buffer = nil
34
38
  @closed = false
@@ -45,29 +49,62 @@ module Protocol
45
49
  # @param buffer [String] the buffer which will receive the data
46
50
  # @return a buffer containing the data
47
51
  def read(length = nil, buffer = nil)
52
+ return '' if length == 0
53
+
48
54
  buffer ||= Async::IO::Buffer.new
49
- buffer.clear
55
+
56
+ # Take any previously buffered data and replace it into the given buffer.
57
+ if @buffer
58
+ buffer.replace(@buffer)
59
+ @buffer = nil
60
+ end
50
61
 
51
- until buffer.bytesize == length
52
- @buffer = read_next if @buffer.nil?
53
- break if @buffer.nil?
62
+ if length
63
+ while buffer.bytesize < length and chunk = read_next
64
+ buffer << chunk
65
+ end
66
+
67
+ # This ensures the subsequent `slice!` works correctly.
68
+ buffer.force_encoding(Encoding::BINARY)
69
+
70
+ # This will be at least one copy:
71
+ @buffer = buffer.byteslice(length, buffer.bytesize)
54
72
 
55
- remaining_length = length - buffer.bytesize if length
73
+ # This should be zero-copy:
74
+ buffer.slice!(length)
56
75
 
57
- if remaining_length && remaining_length < @buffer.bytesize
58
- # We know that we are not going to reuse the original buffer.
59
- # But byteslice will generate a hidden copy. So let's freeze it first:
60
- @buffer.freeze
61
-
62
- buffer << @buffer.byteslice(0, remaining_length)
63
- @buffer = @buffer.byteslice(remaining_length, @buffer.bytesize)
76
+ if buffer.empty?
77
+ return nil
64
78
  else
65
- buffer << @buffer
66
- @buffer = nil
79
+ return buffer
67
80
  end
81
+ else
82
+ while chunk = read_next
83
+ buffer << chunk
84
+ end
85
+
86
+ return buffer
87
+ end
88
+ end
89
+
90
+ # Read at most `length` bytes from the stream. Will avoid reading from the underlying stream if possible.
91
+ def read_partial(length = nil)
92
+ if @buffer
93
+ buffer = @buffer
94
+ @buffer = nil
95
+ else
96
+ buffer = read_next
68
97
  end
69
98
 
70
- return nil if buffer.empty? && length && length > 0
99
+ if buffer and length
100
+ if buffer.bytesize > length
101
+ # This ensures the subsequent `slice!` works correctly.
102
+ buffer.force_encoding(Encoding::BINARY)
103
+
104
+ @buffer = buffer.byteslice(length, buffer.bytesize)
105
+ buffer.slice!(length)
106
+ end
107
+ end
71
108
 
72
109
  return buffer
73
110
  end
@@ -76,6 +113,11 @@ module Protocol
76
113
  @buffer ||= read_next
77
114
  chunk = nil
78
115
 
116
+ unless @buffer
117
+ buffer&.clear
118
+ return
119
+ end
120
+
79
121
  if @buffer.bytesize > length
80
122
  chunk = @buffer.byteslice(0, length)
81
123
  @buffer = @buffer.byteslice(length, @buffer.bytesize)
@@ -94,7 +136,12 @@ module Protocol
94
136
  end
95
137
 
96
138
  def write(buffer)
97
- @output.write(buffer)
139
+ if @output
140
+ @output.write(buffer)
141
+ return buffer.bytesize
142
+ else
143
+ raise IOError, "Stream is not writable, output has been closed!"
144
+ end
98
145
  end
99
146
 
100
147
  alias write_nonblock write
@@ -104,17 +151,21 @@ module Protocol
104
151
 
105
152
  def close_read
106
153
  @input&.close
154
+ @input = nil
107
155
  end
108
156
 
109
157
  # close must never be called on the input stream. huh?
110
158
  def close_write
111
159
  @output&.close
160
+ @output = nil
112
161
  end
113
162
 
114
163
  # Close the input and output bodies.
115
- def close
164
+ def close(error = nil)
116
165
  self.close_read
117
166
  self.close_write
167
+
168
+ return nil
118
169
  ensure
119
170
  @closed = true
120
171
  end
@@ -132,11 +183,11 @@ module Protocol
132
183
  private
133
184
 
134
185
  def read_next
135
- if chunk = @input&.read
136
- return chunk
186
+ if @input
187
+ return @input.read
137
188
  else
138
189
  @input = nil
139
- return nil
190
+ raise IOError, "Stream is not readable, input has been closed!"
140
191
  end
141
192
  end
142
193
  end
@@ -101,20 +101,27 @@ module Protocol
101
101
  # An array of `[key, value]` pairs.
102
102
  attr :fields
103
103
 
104
- # @return the trailer if there are any.
104
+ # @returns Whether there are any trailers.
105
105
  def trailer?
106
106
  @tail != nil
107
107
  end
108
108
 
109
- # Record the current headers, and prepare to receive trailer.
109
+ # Record the current headers, and prepare to add trailers.
110
+ #
111
+ # This method is typically used after headers are sent to capture any
112
+ # additional headers which should then be sent as trailers.
113
+ #
114
+ # A sender that intends to generate one or more trailer fields in a
115
+ # message should generate a trailer header field in the header section of
116
+ # that message to indicate which fields might be present in the trailers.
117
+ #
118
+ # @parameter names [Array] The trailer header names which will be added later.
119
+ # @yields block {|name, value| ...} The trailer headers if any.
120
+ # @returns An enumerator which is suitable for iterating over trailers.
110
121
  def trailer!(&block)
111
122
  @tail ||= @fields.size
112
123
 
113
- return to_enum(:trailer) unless block_given?
114
-
115
- if @tail
116
- @fields.drop(@tail).each(&block)
117
- end
124
+ return trailer(&block)
118
125
  end
119
126
 
120
127
  # Enumerate all headers in the trailer, if there are any.
@@ -22,6 +22,6 @@
22
22
 
23
23
  module Protocol
24
24
  module HTTP
25
- VERSION = "0.22.6"
25
+ VERSION = "0.23.1"
26
26
  end
27
27
  end
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,47 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.6
4
+ version: 0.23.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - Bruno Sutic
9
+ - Bryan Powell
10
+ - Olle Jonsson
11
+ - Yuta Iwama
8
12
  autorequire:
9
13
  bindir: bin
10
- cert_chain: []
11
- date: 2022-04-28 00:00:00.000000000 Z
14
+ cert_chain:
15
+ - |
16
+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EFO9t7XWuFf2SKLmuijgqR4sGDlRsMC4GA1UdEQQnMCWBI3NhbXVlbC53aWxs
33
+ aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWBI3NhbXVlbC53aWxs
34
+ aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEBCwUAA4IBgQB5sxkE
35
+ cBsSYwK6fYpM+hA5B5yZY2+L0Z+27jF1pWGgbhPH8/FjjBLVn+VFok3CDpRqwXCl
36
+ xCO40JEkKdznNy2avOMra6PFiQyOE74kCtv7P+Fdc+FhgqI5lMon6tt9rNeXmnW/
37
+ c1NaMRdxy999hmRGzUSFjozcCwxpy/LwabxtdXwXgSay4mQ32EDjqR1TixS1+smp
38
+ 8C/NCWgpIfzpHGJsjvmH2wAfKtTTqB9CVKLCWEnCHyCaRVuKkrKjqhYCdmMBqCws
39
+ JkxfQWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP
40
+ eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt
41
+ Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
42
+ voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
43
+ -----END CERTIFICATE-----
44
+ date: 2022-08-07 00:00:00.000000000 Z
12
45
  dependencies:
13
46
  - !ruby/object:Gem::Dependency
14
47
  name: bundler
@@ -112,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
145
  - !ruby/object:Gem::Version
113
146
  version: '0'
114
147
  requirements: []
115
- rubygems_version: 3.1.6
148
+ rubygems_version: 3.3.7
116
149
  signing_key:
117
150
  specification_version: 4
118
151
  summary: Provides abstractions to handle HTTP protocols.
metadata.gz.sig ADDED
Binary file