protocol-http 0.22.7 → 0.23.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/protocol/http/body/stream.rb +57 -20
- 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 +36 -3
- 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: 947e9baba3d2edfe763209d4e035c7f985a03ca820340c7ea3175ff309176c5c
|
4
|
+
data.tar.gz: af8d0fb37ac0c458fc4cf4cb314de5c6f0a4167e46a29687b76845a75d12c815
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 133527d39a2eb474635e0cc56a0912c3812b7035bb4e6594a02f392e2275fd014028157198604da3359593351d7b2016ce83db0a28247a0af3f19c01822f004a
|
7
|
+
data.tar.gz: 9d342750268c9cb5e1d33ce339417f5930cc28a3efb3f2f9be0bb608ca751208619f3b11ea598fa022199d7e01512b50445a29c0c2d1dc0fe1616c15fe434568
|
checksums.yaml.gz.sig
ADDED
Binary file
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
#
|
3
3
|
# Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -20,15 +20,19 @@
|
|
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 'buffered'
|
24
|
+
|
23
25
|
module Protocol
|
24
26
|
module HTTP
|
25
27
|
module Body
|
26
28
|
# The input stream is an IO-like object which contains the raw HTTP POST data. When applicable, its external encoding must be “ASCII-8BIT” and it must be opened in binary mode, for Ruby 1.9 compatibility. The input stream must respond to gets, each, read and rewind.
|
27
29
|
class Stream
|
28
|
-
def initialize(input, output)
|
30
|
+
def initialize(input, output = Buffered.new)
|
29
31
|
@input = input
|
30
32
|
@output = output
|
31
33
|
|
34
|
+
raise ArgumentError, "Non-writable output!" unless output.respond_to?(:write)
|
35
|
+
|
32
36
|
# Will hold remaining data in `#read`.
|
33
37
|
@buffer = nil
|
34
38
|
@closed = false
|
@@ -45,29 +49,62 @@ module Protocol
|
|
45
49
|
# @param buffer [String] the buffer which will receive the data
|
46
50
|
# @return a buffer containing the data
|
47
51
|
def read(length = nil, buffer = nil)
|
52
|
+
return '' if length == 0
|
53
|
+
|
48
54
|
buffer ||= Async::IO::Buffer.new
|
49
|
-
|
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
|
50
61
|
|
51
|
-
|
52
|
-
|
53
|
-
|
62
|
+
if length
|
63
|
+
while buffer.bytesize < length and chunk = read_next
|
64
|
+
buffer << chunk
|
65
|
+
end
|
66
|
+
|
67
|
+
# This ensures the subsequent `slice!` works correctly.
|
68
|
+
buffer.force_encoding(Encoding::BINARY)
|
69
|
+
|
70
|
+
# This will be at least one copy:
|
71
|
+
@buffer = buffer.byteslice(length, buffer.bytesize)
|
54
72
|
|
55
|
-
|
73
|
+
# This should be zero-copy:
|
74
|
+
buffer.slice!(length)
|
56
75
|
|
57
|
-
if
|
58
|
-
|
59
|
-
# But byteslice will generate a hidden copy. So let's freeze it first:
|
60
|
-
@buffer.freeze
|
61
|
-
|
62
|
-
buffer << @buffer.byteslice(0, remaining_length)
|
63
|
-
@buffer = @buffer.byteslice(remaining_length, @buffer.bytesize)
|
76
|
+
if buffer.empty?
|
77
|
+
return nil
|
64
78
|
else
|
65
|
-
|
66
|
-
@buffer = nil
|
79
|
+
return buffer
|
67
80
|
end
|
81
|
+
else
|
82
|
+
while chunk = read_next
|
83
|
+
buffer << chunk
|
84
|
+
end
|
85
|
+
|
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
|
68
97
|
end
|
69
98
|
|
70
|
-
|
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)
|
106
|
+
end
|
107
|
+
end
|
71
108
|
|
72
109
|
return buffer
|
73
110
|
end
|
@@ -80,7 +117,7 @@ module Protocol
|
|
80
117
|
buffer&.clear
|
81
118
|
return
|
82
119
|
end
|
83
|
-
|
120
|
+
|
84
121
|
if @buffer.bytesize > length
|
85
122
|
chunk = @buffer.byteslice(0, length)
|
86
123
|
@buffer = @buffer.byteslice(length, @buffer.bytesize)
|
@@ -124,10 +161,10 @@ module Protocol
|
|
124
161
|
end
|
125
162
|
|
126
163
|
# Close the input and output bodies.
|
127
|
-
def close
|
164
|
+
def close(error = nil)
|
128
165
|
self.close_read
|
129
166
|
self.close_write
|
130
|
-
|
167
|
+
|
131
168
|
return nil
|
132
169
|
ensure
|
133
170
|
@closed = true
|
@@ -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
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,47 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protocol-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.23.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
|
+
- Bruno Sutic
|
9
|
+
- Bryan Powell
|
10
|
+
- Olle Jonsson
|
11
|
+
- Yuta Iwama
|
8
12
|
autorequire:
|
9
13
|
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1tEVVUEXmoFCyhzonUUw4nE4CFu/sE3ffhjKcXcY//qiSW
|
31
|
+
xm4erY3XAgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
|
32
|
+
BBYEFO9t7XWuFf2SKLmuijgqR4sGDlRsMC4GA1UdEQQnMCWBI3NhbXVlbC53aWxs
|
33
|
+
aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWBI3NhbXVlbC53aWxs
|
34
|
+
aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEBCwUAA4IBgQB5sxkE
|
35
|
+
cBsSYwK6fYpM+hA5B5yZY2+L0Z+27jF1pWGgbhPH8/FjjBLVn+VFok3CDpRqwXCl
|
36
|
+
xCO40JEkKdznNy2avOMra6PFiQyOE74kCtv7P+Fdc+FhgqI5lMon6tt9rNeXmnW/
|
37
|
+
c1NaMRdxy999hmRGzUSFjozcCwxpy/LwabxtdXwXgSay4mQ32EDjqR1TixS1+smp
|
38
|
+
8C/NCWgpIfzpHGJsjvmH2wAfKtTTqB9CVKLCWEnCHyCaRVuKkrKjqhYCdmMBqCws
|
39
|
+
JkxfQWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP
|
40
|
+
eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt
|
41
|
+
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
42
|
+
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
43
|
+
-----END CERTIFICATE-----
|
44
|
+
date: 2022-08-13 00:00:00.000000000 Z
|
12
45
|
dependencies:
|
13
46
|
- !ruby/object:Gem::Dependency
|
14
47
|
name: bundler
|
metadata.gz.sig
ADDED
Binary file
|