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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/protocol/http/body/buffered.rb +0 -2
- data/lib/protocol/http/body/stream.rb +81 -76
- 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: e75d177999c829771f7425826d9780247d787ae7a145bd6d90db46466c485b6d
|
4
|
+
data.tar.gz: 63bb4af0ed06afe86f513b3c78606fe87d7beec9f38c95d2c1dafe0eb1fa69dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db0297861b7a15bdbe274410952604bf7b8fdb6e981439b2fc42bad0453d71104dbc87c9268b4ba45d5b6f905777cbf2e0065a0c4c6ae3e895b2bc33c34bb679
|
7
|
+
data.tar.gz: c411551f450228472f3010b34bf4069416bbcfb05d9408d2d9d0d058bbb960afb468b66a193c43848b27cb2e1181bc56292b4f2f3171665351a9fca17f1b3fb6
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -41,99 +41,104 @@ module Protocol
|
|
41
41
|
attr :input
|
42
42
|
attr :output
|
43
43
|
|
44
|
-
#
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
68
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
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
|
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.
|
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-
|
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
|