protocol-http 0.45.0 → 0.46.0
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/accept_encoding.rb +15 -3
- data/lib/protocol/http/body/buffered.rb +29 -2
- data/lib/protocol/http/body/completable.rb +13 -0
- data/lib/protocol/http/body/deflate.rb +33 -0
- data/lib/protocol/http/body/digestable.rb +19 -4
- data/lib/protocol/http/body/file.rb +37 -1
- data/lib/protocol/http/body/head.rb +8 -0
- data/lib/protocol/http/body/inflate.rb +10 -2
- data/lib/protocol/http/body/readable.rb +32 -11
- data/lib/protocol/http/body/reader.rb +17 -0
- data/lib/protocol/http/body/rewindable.rb +19 -1
- data/lib/protocol/http/body/stream.rb +34 -6
- data/lib/protocol/http/body/streamable.rb +46 -5
- data/lib/protocol/http/body/wrapper.rb +25 -3
- data/lib/protocol/http/body/writable.rb +48 -7
- data/lib/protocol/http/body.rb +16 -0
- data/lib/protocol/http/content_encoding.rb +13 -3
- data/lib/protocol/http/cookie.rb +23 -0
- data/lib/protocol/http/header/authorization.rb +10 -2
- data/lib/protocol/http/header/cache_control.rb +42 -10
- data/lib/protocol/http/header/connection.rb +18 -1
- data/lib/protocol/http/header/cookie.rb +10 -3
- data/lib/protocol/http/header/date.rb +9 -0
- data/lib/protocol/http/header/etag.rb +11 -0
- data/lib/protocol/http/header/etags.rb +35 -4
- data/lib/protocol/http/header/multiple.rb +9 -1
- data/lib/protocol/http/header/priority.rb +65 -0
- data/lib/protocol/http/header/split.rb +17 -3
- data/lib/protocol/http/header/vary.rb +10 -1
- data/lib/protocol/http/headers.rb +82 -19
- data/lib/protocol/http/methods.rb +5 -0
- data/lib/protocol/http/middleware/builder.rb +17 -0
- data/lib/protocol/http/middleware.rb +28 -0
- data/lib/protocol/http/peer.rb +9 -0
- data/lib/protocol/http/reference.rb +33 -6
- data/lib/protocol/http/request.rb +25 -0
- data/lib/protocol/http/response.rb +12 -0
- data/lib/protocol/http/url.rb +34 -8
- data/lib/protocol/http/version.rb +1 -1
- data/readme.md +4 -0
- data/releases.md +4 -0
- data.tar.gz.sig +0 -0
- metadata +4 -2
- metadata.gz.sig +0 -0
data/lib/protocol/http/url.rb
CHANGED
@@ -6,33 +6,46 @@
|
|
6
6
|
|
7
7
|
module Protocol
|
8
8
|
module HTTP
|
9
|
+
# Helpers for working with URLs.
|
9
10
|
module URL
|
10
|
-
# Escapes a string using percent encoding.
|
11
|
+
# Escapes a string using percent encoding, e.g. `a b` -> `a%20b`.
|
12
|
+
#
|
13
|
+
# @parameter string [String] The string to escape.
|
14
|
+
# @returns [String] The escaped string.
|
11
15
|
def self.escape(string, encoding = string.encoding)
|
12
16
|
string.b.gsub(/([^a-zA-Z0-9_.\-]+)/) do |m|
|
13
17
|
"%" + m.unpack("H2" * m.bytesize).join("%").upcase
|
14
18
|
end.force_encoding(encoding)
|
15
19
|
end
|
16
20
|
|
17
|
-
# Unescapes a percent encoded string.
|
21
|
+
# Unescapes a percent encoded string, e.g. `a%20b` -> `a b`.
|
22
|
+
#
|
23
|
+
# @parameter string [String] The string to unescape.
|
24
|
+
# @returns [String] The unescaped string.
|
18
25
|
def self.unescape(string, encoding = string.encoding)
|
19
26
|
string.b.gsub(/%(\h\h)/) do |hex|
|
20
27
|
Integer($1, 16).chr
|
21
28
|
end.force_encoding(encoding)
|
22
29
|
end
|
23
30
|
|
24
|
-
# According to https://tools.ietf.org/html/rfc3986#section-3.3,
|
25
|
-
|
31
|
+
# Matches characters that are not allowed in a URI path segment. According to RFC 3986 Section 3.3 (https://tools.ietf.org/html/rfc3986#section-3.3), a valid path segment consists of "pchar" characters. This pattern identifies characters that must be percent-encoded when included in a URI path segment.
|
32
|
+
NON_PATH_CHARACTER_PATTERN = /([^a-zA-Z0-9_\-\.~!$&'()*+,;=:@\/]+)/.freeze
|
26
33
|
|
27
|
-
# Escapes non-path characters using percent encoding.
|
34
|
+
# Escapes non-path characters using percent encoding. In other words, this method escapes characters that are not allowed in a URI path segment. According to RFC 3986 Section 3.3 (https://tools.ietf.org/html/rfc3986#section-3.3), a valid path segment consists of "pchar" characters. This method percent-encodes characters that are not "pchar" characters.
|
35
|
+
#
|
36
|
+
# @parameter path [String] The path to escape.
|
37
|
+
# @returns [String] The escaped path.
|
28
38
|
def self.escape_path(path)
|
29
39
|
encoding = path.encoding
|
30
|
-
path.b.gsub(
|
40
|
+
path.b.gsub(NON_PATH_CHARACTER_PATTERN) do |m|
|
31
41
|
"%" + m.unpack("H2" * m.bytesize).join("%").upcase
|
32
42
|
end.force_encoding(encoding)
|
33
43
|
end
|
34
44
|
|
35
|
-
# Encodes a hash or array into a query string.
|
45
|
+
# Encodes a hash or array into a query string. This method is used to encode query parameters in a URL. For example, `{"a" => 1, "b" => 2}` is encoded as `a=1&b=2`.
|
46
|
+
#
|
47
|
+
# @parameter value [Hash | Array | Nil] The value to encode.
|
48
|
+
# @parameter prefix [String] The prefix to use for keys.
|
36
49
|
def self.encode(value, prefix = nil)
|
37
50
|
case value
|
38
51
|
when Array
|
@@ -66,6 +79,10 @@ module Protocol
|
|
66
79
|
end
|
67
80
|
end
|
68
81
|
|
82
|
+
# Split a key into parts, e.g. `a[b][c]` -> `["a", "b", "c"]`.
|
83
|
+
#
|
84
|
+
# @parameter name [String] The key to split.
|
85
|
+
# @returns [Array(String)] The parts of the key.
|
69
86
|
def self.split(name)
|
70
87
|
name.scan(/([^\[]+)|(?:\[(.*?)\])/)&.tap do |parts|
|
71
88
|
parts.flatten!
|
@@ -74,6 +91,10 @@ module Protocol
|
|
74
91
|
end
|
75
92
|
|
76
93
|
# Assign a value to a nested hash.
|
94
|
+
#
|
95
|
+
# @parameter keys [Array(String)] The parts of the key.
|
96
|
+
# @parameter value [Object] The value to assign.
|
97
|
+
# @parameter parent [Hash] The parent hash.
|
77
98
|
def self.assign(keys, value, parent)
|
78
99
|
top, *middle = keys
|
79
100
|
|
@@ -94,7 +115,12 @@ module Protocol
|
|
94
115
|
parent[top] = value
|
95
116
|
end
|
96
117
|
|
97
|
-
#
|
118
|
+
# Decode a URL-encoded query string into a hash.
|
119
|
+
#
|
120
|
+
# @parameter string [String] The query string to decode.
|
121
|
+
# @parameter maximum [Integer] The maximum number of keys in a path.
|
122
|
+
# @parameter symbolize_keys [Boolean] Whether to symbolize keys.
|
123
|
+
# @returns [Hash] The decoded query string.
|
98
124
|
def self.decode(string, maximum = 8, symbolize_keys: false)
|
99
125
|
parameters = {}
|
100
126
|
|
data/readme.md
CHANGED
@@ -24,6 +24,10 @@ Please see the [project documentation](https://socketry.github.io/protocol-http/
|
|
24
24
|
|
25
25
|
Please see the [project releases](https://socketry.github.io/protocol-http/releases/index) for all releases.
|
26
26
|
|
27
|
+
### v0.46.0
|
28
|
+
|
29
|
+
- Add support for `priority:` header.
|
30
|
+
|
27
31
|
### v0.33.0
|
28
32
|
|
29
33
|
- Clarify behaviour of streaming bodies and copy `Protocol::Rack::Body::Streaming` to `Protocol::HTTP::Body::Streamable`.
|
data/releases.md
CHANGED
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.
|
4
|
+
version: 0.46.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -47,7 +47,7 @@ cert_chain:
|
|
47
47
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
48
48
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
49
49
|
-----END CERTIFICATE-----
|
50
|
-
date: 2024-11-
|
50
|
+
date: 2024-11-28 00:00:00.000000000 Z
|
51
51
|
dependencies: []
|
52
52
|
description:
|
53
53
|
email:
|
@@ -57,6 +57,7 @@ extra_rdoc_files: []
|
|
57
57
|
files:
|
58
58
|
- lib/protocol/http.rb
|
59
59
|
- lib/protocol/http/accept_encoding.rb
|
60
|
+
- lib/protocol/http/body.rb
|
60
61
|
- lib/protocol/http/body/buffered.rb
|
61
62
|
- lib/protocol/http/body/completable.rb
|
62
63
|
- lib/protocol/http/body/deflate.rb
|
@@ -82,6 +83,7 @@ files:
|
|
82
83
|
- lib/protocol/http/header/etag.rb
|
83
84
|
- lib/protocol/http/header/etags.rb
|
84
85
|
- lib/protocol/http/header/multiple.rb
|
86
|
+
- lib/protocol/http/header/priority.rb
|
85
87
|
- lib/protocol/http/header/split.rb
|
86
88
|
- lib/protocol/http/header/vary.rb
|
87
89
|
- lib/protocol/http/headers.rb
|
metadata.gz.sig
CHANGED
Binary file
|