protocol-http 0.23.1 → 0.23.4
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/headers.rb +2 -2
- data/lib/protocol/http/request.rb +15 -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: 0a90ddbbf77b6838a596c01ff6bc77d7f67867eb91cc3560d92da5458a011af9
|
4
|
+
data.tar.gz: 803a2218c2d60270c8eca75f49d1063a1b61fd45d66a0313d6e20a0abf2d0587
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36f23a497f933e91cf8ca08e367faeaba6539fdafc86587aca27d0ad7e4f2c2d7fe4f3224f9f7509f07e5fdabf733a72c875a7cb2ba29d507b3dcba5b1af6777
|
7
|
+
data.tar.gz: 056d805e7795929d8af1609e490bb4ff86b7c9e083c585ed08aee68ea810ba9fddcc3beceb1ec0102e245cbf6f2a2712c03bbf8d83a153b0eac4ce369ef4f54b
|
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)
|
@@ -340,11 +340,11 @@ module Protocol
|
|
340
340
|
return self
|
341
341
|
end
|
342
342
|
|
343
|
-
# @
|
343
|
+
# @yields [String, String] header key (lower case string) and value (as string).
|
344
344
|
def each(&block)
|
345
345
|
@all.each do |headers|
|
346
346
|
headers.each do |key, value|
|
347
|
-
yield key.downcase, value.to_s
|
347
|
+
yield key.to_s.downcase, value.to_s
|
348
348
|
end
|
349
349
|
end
|
350
350
|
end
|
@@ -39,13 +39,28 @@ module Protocol
|
|
39
39
|
@protocol = protocol
|
40
40
|
end
|
41
41
|
|
42
|
+
# The request scheme, usually one of "http" or "https".
|
42
43
|
attr_accessor :scheme
|
44
|
+
|
45
|
+
# The request authority, usually a hostname and port number.
|
43
46
|
attr_accessor :authority
|
47
|
+
|
48
|
+
# The request method, usually one of "GET", "HEAD", "POST", "PUT", "DELETE", "CONNECT" or "OPTIONS".
|
44
49
|
attr_accessor :method
|
50
|
+
|
51
|
+
# The request path, usually a path and query string.
|
45
52
|
attr_accessor :path
|
53
|
+
|
54
|
+
# The request version, usually "http/1.0", "http/1.1", "h2", or "h3".
|
46
55
|
attr_accessor :version
|
56
|
+
|
57
|
+
# The request headers, contains metadata associated with the request such as the user agent, accept (content type), accept-language, etc.
|
47
58
|
attr_accessor :headers
|
59
|
+
|
60
|
+
# The request body, an instance of Protocol::HTTP::Body::Readable or similar.
|
48
61
|
attr_accessor :body
|
62
|
+
|
63
|
+
# The request protocol, usually empty, but occasionally "websocket" or "webtransport", can be either single value `String` or multi-value `Array` of `String` instances. In HTTP/1, it is used to request a connection upgrade, and in HTTP/2 it is used to indicate a specfic protocol for the stream.
|
49
64
|
attr_accessor :protocol
|
50
65
|
|
51
66
|
# Send the request to the given connection.
|
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.4
|
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
|