protocol-http 0.23.2 → 0.23.5

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: 647e0b3ea883053a0181b4a47623893d9cf9a9effdbe4ebb001fc4788ac504fc
4
+ data.tar.gz: a8b9f1d185f320acc1f84c5af015bc28ac0cbd165bb2c92ab8c6b9f950e311db
5
5
  SHA512:
6
- metadata.gz: 133527d39a2eb474635e0cc56a0912c3812b7035bb4e6594a02f392e2275fd014028157198604da3359593351d7b2016ce83db0a28247a0af3f19c01822f004a
7
- data.tar.gz: 9d342750268c9cb5e1d33ce339417f5930cc28a3efb3f2f9be0bb608ca751208619f3b11ea598fa022199d7e01512b50445a29c0c2d1dc0fe1616c15fe434568
6
+ metadata.gz: 7193d7634fb0a006320f6199ba3a2ac1985412f9dfe46bc6610745741088045c14ef561efb5d9efa4e9de42ac797fe4d778f28eb6c5442ae482c733a8f273e4b
7
+ data.tar.gz: 03c36e9c6f5010bdcdbc1dc4c26ea19e55169897eba6efb0b1bf0fe98498f205c364093045f44307d15c4f65bac7ccc05e4a0d4624427b319e7b9b138ea9cd39
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,100 +41,107 @@ 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
53
-
54
- buffer ||= Async::IO::Buffer.new
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
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?
61
48
 
62
- if length
63
- while buffer.bytesize < length and chunk = read_next
64
- buffer << chunk
65
- end
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
66
55
 
67
- # This ensures the subsequent `slice!` works correctly.
68
- buffer.force_encoding(Encoding::BINARY)
56
+ buffer ||= Async::IO::Buffer.new
69
57
 
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
58
+ # Take any previously buffered data and replace it into the given buffer.
59
+ if @buffer
60
+ buffer.replace(@buffer)
61
+ @buffer = nil
78
62
  else
79
- return buffer
80
- end
81
- else
82
- while chunk = read_next
83
- buffer << chunk
63
+ buffer.clear
84
64
  end
85
65
 
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
97
- end
98
-
99
- if buffer and length
100
- if buffer.bytesize > length
66
+ if length
67
+ while buffer.bytesize < length and chunk = read_next
68
+ buffer << chunk
69
+ end
70
+
101
71
  # This ensures the subsequent `slice!` works correctly.
102
72
  buffer.force_encoding(Encoding::BINARY)
103
73
 
74
+ # This will be at least one copy:
104
75
  @buffer = buffer.byteslice(length, buffer.bytesize)
105
- buffer.slice!(length)
76
+
77
+ # This should be zero-copy:
78
+ buffer.slice!(length, buffer.bytesize)
79
+
80
+ if buffer.empty?
81
+ return nil
82
+ else
83
+ return buffer
84
+ end
85
+ else
86
+ while chunk = read_next
87
+ buffer << chunk
88
+ end
89
+
90
+ return buffer
106
91
  end
107
92
  end
108
93
 
109
- return buffer
110
- end
111
-
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
94
+ # Read at most `length` bytes from the stream. Will avoid reading from the underlying stream if possible.
95
+ def read_partial(length = nil)
96
+ if @buffer
97
+ buffer = @buffer
98
+ @buffer = nil
99
+ else
100
+ buffer = read_next
101
+ end
102
+
103
+ if buffer and length
104
+ if buffer.bytesize > length
105
+ # This ensures the subsequent `slice!` works correctly.
106
+ buffer.force_encoding(Encoding::BINARY)
107
+
108
+ @buffer = buffer.byteslice(length, buffer.bytesize)
109
+ buffer.slice!(length, buffer.bytesize)
110
+ end
111
+ end
112
+
113
+ return buffer
127
114
  end
128
115
 
129
- if buffer
130
- buffer.replace(chunk)
131
- else
132
- buffer = chunk
116
+ def read_nonblock(length, buffer = nil)
117
+ @buffer ||= read_next
118
+ chunk = nil
119
+
120
+ unless @buffer
121
+ buffer&.clear
122
+ return
123
+ end
124
+
125
+ if @buffer.bytesize > length
126
+ chunk = @buffer.byteslice(0, length)
127
+ @buffer = @buffer.byteslice(length, @buffer.bytesize)
128
+ else
129
+ chunk = @buffer
130
+ @buffer = nil
131
+ end
132
+
133
+ if buffer
134
+ buffer.replace(chunk)
135
+ else
136
+ buffer = chunk
137
+ end
138
+
139
+ return buffer
133
140
  end
134
-
135
- return buffer
136
141
  end
137
142
 
143
+ include Reader
144
+
138
145
  def write(buffer)
139
146
  if @output
140
147
  @output.write(buffer)
@@ -20,7 +20,7 @@
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 '../headers'
23
+ require_relative '../middleware'
24
24
 
25
25
  module Protocol
26
26
  module HTTP
@@ -67,6 +67,15 @@ module Protocol
67
67
  Response[200, Headers['content-type' => 'text/plain'], ["Hello World!"]]
68
68
  end
69
69
  end
70
+
71
+ module NotFound
72
+ def self.close
73
+ end
74
+
75
+ def self.call(request)
76
+ Response[404, Headers[], []]
77
+ end
78
+ end
70
79
  end
71
80
  end
72
81
  end
@@ -22,6 +22,6 @@
22
22
 
23
23
  module Protocol
24
24
  module HTTP
25
- VERSION = "0.23.2"
25
+ VERSION = "0.23.5"
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.5
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-21 00:00:00.000000000 Z
45
45
  dependencies:
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: bundler
metadata.gz.sig CHANGED
Binary file