protocol-http 0.23.2 → 0.23.3

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: 947e9baba3d2edfe763209d4e035c7f985a03ca820340c7ea3175ff309176c5c
4
- data.tar.gz: af8d0fb37ac0c458fc4cf4cb314de5c6f0a4167e46a29687b76845a75d12c815
3
+ metadata.gz: e75d177999c829771f7425826d9780247d787ae7a145bd6d90db46466c485b6d
4
+ data.tar.gz: 63bb4af0ed06afe86f513b3c78606fe87d7beec9f38c95d2c1dafe0eb1fa69dc
5
5
  SHA512:
6
- metadata.gz: 133527d39a2eb474635e0cc56a0912c3812b7035bb4e6594a02f392e2275fd014028157198604da3359593351d7b2016ce83db0a28247a0af3f19c01822f004a
7
- data.tar.gz: 9d342750268c9cb5e1d33ce339417f5930cc28a3efb3f2f9be0bb608ca751208619f3b11ea598fa022199d7e01512b50445a29c0c2d1dc0fe1616c15fe434568
6
+ metadata.gz: db0297861b7a15bdbe274410952604bf7b8fdb6e981439b2fc42bad0453d71104dbc87c9268b4ba45d5b6f905777cbf2e0065a0c4c6ae3e895b2bc33c34bb679
7
+ data.tar.gz: c411551f450228472f3010b34bf4069416bbcfb05d9408d2d9d0d058bbb960afb468b66a193c43848b27cb2e1181bc56292b4f2f3171665351a9fca17f1b3fb6
checksums.yaml.gz.sig CHANGED
Binary file
@@ -56,7 +56,6 @@ module Protocol
56
56
  @length = length
57
57
 
58
58
  @index = 0
59
- @digest = nil
60
59
  end
61
60
 
62
61
  attr :chunks
@@ -87,7 +86,6 @@ module Protocol
87
86
  end
88
87
 
89
88
  def write(chunk)
90
- @digest&.update(chunk)
91
89
  @chunks << chunk
92
90
  end
93
91
 
@@ -41,99 +41,104 @@ module Protocol
41
41
  attr :input
42
42
  attr :output
43
43
 
44
- # rack.hijack_io must respond to:
45
- # read, write, read_nonblock, write_nonblock, flush, close, close_read, close_write, closed?
46
-
47
- # read behaves like IO#read. Its signature is read([length, [buffer]]). If given, length must be a non-negative Integer (>= 0) or nil, and buffer must be a String and may not be nil. If length is given and not nil, then this method reads at most length bytes from the input stream. If length is not given or nil, then this method reads all data until EOF. When EOF is reached, this method returns nil if length is given and not nil, or “” if length is not given or is nil. If buffer is given, then the read data will be placed into buffer instead of a newly created String object.
48
- # @param length [Integer] the amount of data to read
49
- # @param buffer [String] the buffer which will receive the data
50
- # @return a buffer containing the data
51
- def read(length = nil, buffer = nil)
52
- return '' if length == 0
44
+ # This provides a read-only interface for data, which is surprisingly tricky to implement correctly.
45
+ module Reader
46
+ # rack.hijack_io must respond to:
47
+ # read, write, read_nonblock, write_nonblock, flush, close, close_read, close_write, closed?
53
48
 
54
- buffer ||= Async::IO::Buffer.new
49
+ # read behaves like IO#read. Its signature is read([length, [buffer]]). If given, length must be a non-negative Integer (>= 0) or nil, and buffer must be a String and may not be nil. If length is given and not nil, then this method reads at most length bytes from the input stream. If length is not given or nil, then this method reads all data until EOF. When EOF is reached, this method returns nil if length is given and not nil, or “” if length is not given or is nil. If buffer is given, then the read data will be placed into buffer instead of a newly created String object.
50
+ # @param length [Integer] the amount of data to read
51
+ # @param buffer [String] the buffer which will receive the data
52
+ # @return a buffer containing the data
53
+ def read(length = nil, buffer = nil)
54
+ return '' if length == 0
55
+
56
+ buffer ||= Async::IO::Buffer.new
55
57
 
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
61
-
62
- if length
63
- while buffer.bytesize < length and chunk = read_next
64
- buffer << chunk
58
+ # Take any previously buffered data and replace it into the given buffer.
59
+ if @buffer
60
+ buffer.replace(@buffer)
61
+ @buffer = nil
65
62
  end
66
63
 
67
- # This ensures the subsequent `slice!` works correctly.
68
- buffer.force_encoding(Encoding::BINARY)
64
+ if length
65
+ while buffer.bytesize < length and chunk = read_next
66
+ buffer << chunk
67
+ end
68
+
69
+ # This ensures the subsequent `slice!` works correctly.
70
+ buffer.force_encoding(Encoding::BINARY)
69
71
 
70
- # This will be at least one copy:
71
- @buffer = buffer.byteslice(length, buffer.bytesize)
72
-
73
- # This should be zero-copy:
74
- buffer.slice!(length)
75
-
76
- if buffer.empty?
77
- return nil
72
+ # This will be at least one copy:
73
+ @buffer = buffer.byteslice(length, buffer.bytesize)
74
+
75
+ # This should be zero-copy:
76
+ buffer.slice!(length, buffer.bytesize)
77
+
78
+ if buffer.empty?
79
+ return nil
80
+ else
81
+ return buffer
82
+ end
78
83
  else
84
+ while chunk = read_next
85
+ buffer << chunk
86
+ end
87
+
79
88
  return buffer
80
89
  end
81
- else
82
- while chunk = read_next
83
- buffer << chunk
90
+ end
91
+
92
+ # Read at most `length` bytes from the stream. Will avoid reading from the underlying stream if possible.
93
+ def read_partial(length = nil)
94
+ if @buffer
95
+ buffer = @buffer
96
+ @buffer = nil
97
+ else
98
+ buffer = read_next
99
+ end
100
+
101
+ if buffer and length
102
+ if buffer.bytesize > length
103
+ # This ensures the subsequent `slice!` works correctly.
104
+ buffer.force_encoding(Encoding::BINARY)
105
+
106
+ @buffer = buffer.byteslice(length, buffer.bytesize)
107
+ buffer.slice!(length, buffer.bytesize)
108
+ end
84
109
  end
85
110
 
86
111
  return buffer
87
112
  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
97
- end
98
113
 
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)
114
+ def read_nonblock(length, buffer = nil)
115
+ @buffer ||= read_next
116
+ chunk = nil
117
+
118
+ unless @buffer
119
+ buffer&.clear
120
+ return
121
+ end
122
+
123
+ if @buffer.bytesize > length
124
+ chunk = @buffer.byteslice(0, length)
125
+ @buffer = @buffer.byteslice(length, @buffer.bytesize)
126
+ else
127
+ chunk = @buffer
128
+ @buffer = nil
106
129
  end
130
+
131
+ if buffer
132
+ buffer.replace(chunk)
133
+ else
134
+ buffer = chunk
135
+ end
136
+
137
+ return buffer
107
138
  end
108
-
109
- return buffer
110
139
  end
111
140
 
112
- def read_nonblock(length, buffer = nil)
113
- @buffer ||= read_next
114
- chunk = nil
115
-
116
- unless @buffer
117
- buffer&.clear
118
- return
119
- end
120
-
121
- if @buffer.bytesize > length
122
- chunk = @buffer.byteslice(0, length)
123
- @buffer = @buffer.byteslice(length, @buffer.bytesize)
124
- else
125
- chunk = @buffer
126
- @buffer = nil
127
- end
128
-
129
- if buffer
130
- buffer.replace(chunk)
131
- else
132
- buffer = chunk
133
- end
134
-
135
- return buffer
136
- end
141
+ include Reader
137
142
 
138
143
  def write(buffer)
139
144
  if @output
@@ -22,6 +22,6 @@
22
22
 
23
23
  module Protocol
24
24
  module HTTP
25
- VERSION = "0.23.2"
25
+ VERSION = "0.23.3"
26
26
  end
27
27
  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.23.2
4
+ version: 0.23.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -41,7 +41,7 @@ cert_chain:
41
41
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
42
42
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
43
43
  -----END CERTIFICATE-----
44
- date: 2022-08-13 00:00:00.000000000 Z
44
+ date: 2022-08-15 00:00:00.000000000 Z
45
45
  dependencies:
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: bundler
metadata.gz.sig CHANGED
Binary file