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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/protocol/http/body/buffered.rb +0 -2
- data/lib/protocol/http/body/stream.rb +83 -76
- data/lib/protocol/http/middleware/builder.rb +1 -1
- data/lib/protocol/http/middleware.rb +9 -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: 647e0b3ea883053a0181b4a47623893d9cf9a9effdbe4ebb001fc4788ac504fc
|
4
|
+
data.tar.gz: a8b9f1d185f320acc1f84c5af015bc28ac0cbd165bb2c92ab8c6b9f950e311db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7193d7634fb0a006320f6199ba3a2ac1985412f9dfe46bc6610745741088045c14ef561efb5d9efa4e9de42ac797fe4d778f28eb6c5442ae482c733a8f273e4b
|
7
|
+
data.tar.gz: 03c36e9c6f5010bdcdbc1dc4c26ea19e55169897eba6efb0b1bf0fe98498f205c364093045f44307d15c4f65bac7ccc05e4a0d4624427b319e7b9b138ea9cd39
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -41,100 +41,107 @@ 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
|
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
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
68
|
-
buffer.force_encoding(Encoding::BINARY)
|
56
|
+
buffer ||= Async::IO::Buffer.new
|
69
57
|
|
70
|
-
#
|
71
|
-
@buffer
|
72
|
-
|
73
|
-
|
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
|
-
|
80
|
-
end
|
81
|
-
else
|
82
|
-
while chunk = read_next
|
83
|
-
buffer << chunk
|
63
|
+
buffer.clear
|
84
64
|
end
|
85
65
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
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
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
-
|
130
|
-
buffer
|
131
|
-
|
132
|
-
|
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)
|
@@ -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
|
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.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-
|
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
|