protocol-http 0.22.4 → 0.22.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/protocol/http/body/readable.rb +1 -1
- data/lib/protocol/http/body/stream.rb +18 -4
- data/lib/protocol/http/cookie.rb +2 -2
- data/lib/protocol/http/headers.rb +14 -9
- data/lib/protocol/http/url.rb +9 -5
- data/lib/protocol/http/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3941486c86fe210a4ba79c2c77c73bfa3de8cd7cfbfe892c4b6d0b48699260c2
|
4
|
+
data.tar.gz: afd65fb56ed88d184249ab56d87271f6926d398e8460135315e571b1848416a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10e885a3c13ec3a380c774b62e4e5fdd1a0a378766eca8650733909917ab964ccb85b39aa39105d522d8efd93b917a546029c1d70260fef4ba719c984f055926
|
7
|
+
data.tar.gz: b67aa62dc2d4f5e5c3e6d97cd4f40044de8a7b02dac0343aa796dcdf936171f3ec097819d3e70ec4af76ec493496c3507b6ec62302571b76b5ac359e9d015641
|
@@ -76,6 +76,11 @@ module Protocol
|
|
76
76
|
@buffer ||= read_next
|
77
77
|
chunk = nil
|
78
78
|
|
79
|
+
unless @buffer
|
80
|
+
buffer&.clear
|
81
|
+
return
|
82
|
+
end
|
83
|
+
|
79
84
|
if @buffer.bytesize > length
|
80
85
|
chunk = @buffer.byteslice(0, length)
|
81
86
|
@buffer = @buffer.byteslice(length, @buffer.bytesize)
|
@@ -94,7 +99,12 @@ module Protocol
|
|
94
99
|
end
|
95
100
|
|
96
101
|
def write(buffer)
|
97
|
-
@output
|
102
|
+
if @output
|
103
|
+
@output.write(buffer)
|
104
|
+
return buffer.bytesize
|
105
|
+
else
|
106
|
+
raise IOError, "Stream is not writable, output has been closed!"
|
107
|
+
end
|
98
108
|
end
|
99
109
|
|
100
110
|
alias write_nonblock write
|
@@ -104,17 +114,21 @@ module Protocol
|
|
104
114
|
|
105
115
|
def close_read
|
106
116
|
@input&.close
|
117
|
+
@input = nil
|
107
118
|
end
|
108
119
|
|
109
120
|
# close must never be called on the input stream. huh?
|
110
121
|
def close_write
|
111
122
|
@output&.close
|
123
|
+
@output = nil
|
112
124
|
end
|
113
125
|
|
114
126
|
# Close the input and output bodies.
|
115
127
|
def close
|
116
128
|
self.close_read
|
117
129
|
self.close_write
|
130
|
+
|
131
|
+
return nil
|
118
132
|
ensure
|
119
133
|
@closed = true
|
120
134
|
end
|
@@ -132,11 +146,11 @@ module Protocol
|
|
132
146
|
private
|
133
147
|
|
134
148
|
def read_next
|
135
|
-
if
|
136
|
-
return
|
149
|
+
if @input
|
150
|
+
return @input.read
|
137
151
|
else
|
138
152
|
@input = nil
|
139
|
-
|
153
|
+
raise IOError, "Stream is not readable, input has been closed!"
|
140
154
|
end
|
141
155
|
end
|
142
156
|
end
|
data/lib/protocol/http/cookie.rb
CHANGED
@@ -101,22 +101,27 @@ module Protocol
|
|
101
101
|
# An array of `[key, value]` pairs.
|
102
102
|
attr :fields
|
103
103
|
|
104
|
-
# @
|
104
|
+
# @returns Whether there are any trailers.
|
105
105
|
def trailer?
|
106
106
|
@tail != nil
|
107
107
|
end
|
108
108
|
|
109
|
-
# Record the current headers, and prepare to
|
109
|
+
# Record the current headers, and prepare to add trailers.
|
110
|
+
#
|
111
|
+
# This method is typically used after headers are sent to capture any
|
112
|
+
# additional headers which should then be sent as trailers.
|
113
|
+
#
|
114
|
+
# A sender that intends to generate one or more trailer fields in a
|
115
|
+
# message should generate a trailer header field in the header section of
|
116
|
+
# that message to indicate which fields might be present in the trailers.
|
117
|
+
#
|
118
|
+
# @parameter names [Array] The trailer header names which will be added later.
|
119
|
+
# @yields block {|name, value| ...} The trailer headers if any.
|
120
|
+
# @returns An enumerator which is suitable for iterating over trailers.
|
110
121
|
def trailer!(&block)
|
111
|
-
return nil unless self.include?(TRAILER)
|
112
|
-
|
113
122
|
@tail ||= @fields.size
|
114
123
|
|
115
|
-
return
|
116
|
-
|
117
|
-
if @tail
|
118
|
-
@fields.drop(@tail).each(&block)
|
119
|
-
end
|
124
|
+
return trailer(&block)
|
120
125
|
end
|
121
126
|
|
122
127
|
# Enumerate all headers in the trailer, if there are any.
|
data/lib/protocol/http/url.rb
CHANGED
@@ -23,13 +23,14 @@
|
|
23
23
|
module Protocol
|
24
24
|
module HTTP
|
25
25
|
module URL
|
26
|
-
# Escapes a
|
26
|
+
# Escapes a string using percent encoding.
|
27
27
|
def self.escape(string, encoding = string.encoding)
|
28
28
|
string.b.gsub(/([^a-zA-Z0-9_.\-]+)/) do |m|
|
29
29
|
'%' + m.unpack('H2' * m.bytesize).join('%').upcase
|
30
30
|
end.force_encoding(encoding)
|
31
31
|
end
|
32
32
|
|
33
|
+
# Unescapes a percent encoded string.
|
33
34
|
def self.unescape(string, encoding = string.encoding)
|
34
35
|
string.b.gsub(/%(\h\h)/) do |hex|
|
35
36
|
Integer(hex, 16).chr
|
@@ -39,7 +40,7 @@ module Protocol
|
|
39
40
|
# According to https://tools.ietf.org/html/rfc3986#section-3.3, we escape non-pchar.
|
40
41
|
NON_PCHAR = /([^a-zA-Z0-9_\-\.~!$&'()*+,;=:@\/]+)/.freeze
|
41
42
|
|
42
|
-
# Escapes
|
43
|
+
# Escapes non-path characters using percent encoding.
|
43
44
|
def self.escape_path(path)
|
44
45
|
encoding = path.encoding
|
45
46
|
path.b.gsub(NON_PCHAR) do |m|
|
@@ -47,7 +48,7 @@ module Protocol
|
|
47
48
|
end.force_encoding(encoding)
|
48
49
|
end
|
49
50
|
|
50
|
-
# Encodes a hash or array into a query string
|
51
|
+
# Encodes a hash or array into a query string.
|
51
52
|
def self.encode(value, prefix = nil)
|
52
53
|
case value
|
53
54
|
when Array
|
@@ -67,9 +68,12 @@ module Protocol
|
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
71
|
+
# Scan a string for URL-encoded key/value pairs.
|
72
|
+
# @yields {|key, value| ...}
|
73
|
+
# @parameter key [String] The unescaped key.
|
74
|
+
# @parameter value [String] The unescaped key.
|
70
75
|
def self.scan(string)
|
71
|
-
|
72
|
-
string.split('&').each do |assignment|
|
76
|
+
string.split('&') do |assignment|
|
73
77
|
key, value = assignment.split('=', 2)
|
74
78
|
|
75
79
|
yield unescape(key), unescape(value)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protocol-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.22.
|
4
|
+
version: 0.22.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
|
-
rubygems_version: 3.
|
115
|
+
rubygems_version: 3.3.7
|
116
116
|
signing_key:
|
117
117
|
specification_version: 4
|
118
118
|
summary: Provides abstractions to handle HTTP protocols.
|