linzer 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.standard.yml +2 -4
- data/CHANGELOG.md +8 -0
- data/README.md +3 -0
- data/lib/linzer/message.rb +119 -28
- data/lib/linzer/request.rb +1 -0
- data/lib/linzer/response.rb +1 -1
- data/lib/linzer/version.rb +5 -1
- data/linzer.gemspec +3 -3
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c09a63a7eae654921b40e0462b463b3e70867522fcedaf42f03373dd72ef55a5
|
4
|
+
data.tar.gz: b5fea79104954db4289fbf7e4df9f8e589827943cb62eb2836bd0b970611263a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89572382dde42b597eeafecceca1572222cff5d20bba50345b0e3849f47d510cdbcfbc0988295e16b783aa9d28235a95e56b49302a53577e744dc8575253a419
|
7
|
+
data.tar.gz: bc8c2850994c211b4549dcd07d64ddb14fd54d948a05153d8011042eb4cd2b4adca4d8f80ab983a8c8c71deefc2473994fa479ec8b7ec00063dfa86ead7be7a4
|
data/.standard.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.6.0] - 2024-04-06
|
4
|
+
|
5
|
+
- Support parameters on HTTP field component identifiers.
|
6
|
+
|
7
|
+
- Add a work-around for failed unit-tests in ruby HEAD CI jobs.
|
8
|
+
|
9
|
+
- Set up simplecov and improve unit-tests coverage.
|
10
|
+
|
3
11
|
## [0.5.2] - 2024-04-02
|
4
12
|
|
5
13
|
- Make all unit tests pass on Ruby 3.0:
|
data/README.md
CHANGED
@@ -159,6 +159,9 @@ Please note that is still early days and extensive testing is still ongoing. For
|
|
159
159
|
I'll be expanding the library to cover more functionality specified in the RFC
|
160
160
|
in subsequent releases.
|
161
161
|
|
162
|
+
## Ruby version compatibility
|
163
|
+
|
164
|
+
linzer is built in [Continuous Integration](https://github.com/nomadium/linzer/actions/workflows/main.yml) on Ruby 3.0+.
|
162
165
|
|
163
166
|
## Development
|
164
167
|
|
data/lib/linzer/message.rb
CHANGED
@@ -2,8 +2,10 @@
|
|
2
2
|
|
3
3
|
module Linzer
|
4
4
|
class Message
|
5
|
-
def initialize(operation)
|
5
|
+
def initialize(operation, attached_request: nil)
|
6
6
|
@operation = operation
|
7
|
+
validate
|
8
|
+
@attached_request = attached_request ? Message.new(attached_request) : nil
|
7
9
|
freeze
|
8
10
|
end
|
9
11
|
|
@@ -15,6 +17,10 @@ module Linzer
|
|
15
17
|
@operation.is_a?(Rack::Response) || @operation.respond_to?(:status)
|
16
18
|
end
|
17
19
|
|
20
|
+
def attached_request?
|
21
|
+
!!@attached_request
|
22
|
+
end
|
23
|
+
|
18
24
|
def headers
|
19
25
|
return @operation.headers if response? || @operation.respond_to?(:headers)
|
20
26
|
|
@@ -26,32 +32,26 @@ module Linzer
|
|
26
32
|
end
|
27
33
|
|
28
34
|
DERIVED_COMPONENT = {
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
"
|
34
|
-
|
35
|
-
"
|
36
|
-
|
35
|
+
method: :request_method,
|
36
|
+
authority: :authority,
|
37
|
+
path: :path_info,
|
38
|
+
status: :status,
|
39
|
+
"target-uri": :url,
|
40
|
+
scheme: :scheme,
|
41
|
+
"request-target": :fullpath,
|
42
|
+
query: :query_string
|
37
43
|
}.freeze
|
38
44
|
|
39
45
|
def [](field_name)
|
40
|
-
|
41
|
-
|
42
|
-
return @operation.headers[field_name] # if response?
|
43
|
-
end
|
46
|
+
name = parse_field_name(field_name)
|
47
|
+
return nil if name.nil?
|
44
48
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
when /\A(?<field>(?<prefix>@query-param)(?<rest>;name=.+)\Z)/
|
51
|
-
return parse_query_param Regexp.last_match
|
49
|
+
if field_name.start_with?("@")
|
50
|
+
return nil if name.parameters["tr"]
|
51
|
+
retrieve(name, :derived)
|
52
|
+
else
|
53
|
+
retrieve(name, :field)
|
52
54
|
end
|
53
|
-
|
54
|
-
method ? @operation.public_send(method) : nil
|
55
55
|
end
|
56
56
|
|
57
57
|
class << self
|
@@ -64,14 +64,105 @@ module Linzer
|
|
64
64
|
|
65
65
|
private
|
66
66
|
|
67
|
-
def
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
def validate
|
68
|
+
msg = "Message instance must be an HTTP request or response"
|
69
|
+
raise Error.new msg if response? == request?
|
70
|
+
end
|
71
|
+
|
72
|
+
def parse_field_name(field_name)
|
73
|
+
if field_name&.start_with?("@")
|
74
|
+
Starry.parse_item(field_name[1..])
|
75
|
+
else
|
76
|
+
Starry.parse_item(field_name)
|
77
|
+
end
|
78
|
+
rescue => _
|
79
|
+
nil
|
80
|
+
end
|
81
|
+
|
82
|
+
def retrieve(name, method)
|
83
|
+
has_req = name.parameters["req"]
|
84
|
+
has_sf = name.parameters["sf"] || name.parameters.key?("key")
|
85
|
+
has_bs = name.parameters["bs"]
|
86
|
+
|
87
|
+
return nil if has_req && (!response? || !attached_request?)
|
88
|
+
|
89
|
+
if has_req
|
90
|
+
name.parameters.delete("req")
|
91
|
+
return req(name, method)
|
92
|
+
end
|
93
|
+
|
94
|
+
value = send(method, name)
|
95
|
+
|
96
|
+
key = name.parameters["key"]
|
97
|
+
value = sf(value, key) if has_sf
|
98
|
+
value = bs(value) if has_bs
|
99
|
+
value
|
100
|
+
end
|
101
|
+
|
102
|
+
def derived(name)
|
103
|
+
method = DERIVED_COMPONENT[name.value]
|
104
|
+
|
105
|
+
value = case name.value
|
106
|
+
when :query then derive(@operation, method)
|
107
|
+
when :"query-param" then query_param(name)
|
108
|
+
end
|
109
|
+
|
110
|
+
return nil if !method && !value
|
111
|
+
value || derive(@operation, method)
|
112
|
+
end
|
113
|
+
|
114
|
+
def field(name)
|
115
|
+
has_tr = name.parameters["tr"]
|
116
|
+
if has_tr
|
117
|
+
value = tr(name)
|
118
|
+
else
|
119
|
+
if request?
|
120
|
+
rack_header_name = Request.rack_header_name(name.value.to_s)
|
121
|
+
value = @operation.env[rack_header_name]
|
122
|
+
end
|
123
|
+
value = @operation.headers[name.value.to_s] if response?
|
124
|
+
end
|
125
|
+
value.dup&.strip
|
126
|
+
end
|
127
|
+
|
128
|
+
def derive(operation, method)
|
129
|
+
return nil unless operation.respond_to?(method)
|
130
|
+
value = operation.public_send(method)
|
131
|
+
return "?" + value if method == :query_string
|
132
|
+
value
|
133
|
+
end
|
134
|
+
|
135
|
+
def query_param(name)
|
136
|
+
param_name = name.parameters["name"]
|
137
|
+
return nil if !param_name
|
138
|
+
decoded_param_name = URI.decode_uri_component(param_name)
|
139
|
+
URI.encode_uri_component(@operation.params.fetch(decoded_param_name))
|
73
140
|
rescue => _
|
74
141
|
nil
|
75
142
|
end
|
143
|
+
|
144
|
+
def sf(value, key = nil)
|
145
|
+
dict = Starry.parse_dictionary(value)
|
146
|
+
|
147
|
+
obj = dict[key] if key
|
148
|
+
return Starry.serialize(obj.is_a?(Starry::InnerList) ? [obj] : obj) if key
|
149
|
+
|
150
|
+
Starry.serialize(dict)
|
151
|
+
end
|
152
|
+
|
153
|
+
def bs(value)
|
154
|
+
Starry.serialize(value.encode(Encoding::ASCII_8BIT))
|
155
|
+
end
|
156
|
+
|
157
|
+
def tr(trailer)
|
158
|
+
@operation.body.trailers[trailer.value.to_s]
|
159
|
+
end
|
160
|
+
|
161
|
+
def req(field, method)
|
162
|
+
case method
|
163
|
+
when :derived then @attached_request["@#{field}"]
|
164
|
+
when :field then @attached_request[field.to_s]
|
165
|
+
end
|
166
|
+
end
|
76
167
|
end
|
77
168
|
end
|
data/lib/linzer/request.rb
CHANGED
data/lib/linzer/response.rb
CHANGED
data/lib/linzer/version.rb
CHANGED
data/linzer.gemspec
CHANGED
@@ -29,9 +29,9 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
30
|
spec.require_paths = ["lib"]
|
31
31
|
|
32
|
-
spec.add_runtime_dependency "openssl", ">= 3.0.0"
|
32
|
+
spec.add_runtime_dependency "openssl", "~> 3.0", ">= 3.0.0"
|
33
33
|
spec.add_runtime_dependency "ed25519", "~> 1.3", ">= 1.3.0"
|
34
|
-
spec.add_runtime_dependency "starry", "~> 0.1"
|
34
|
+
spec.add_runtime_dependency "starry", "~> 0.1" unless Linzer.ruby_dev?
|
35
35
|
spec.add_runtime_dependency "rack", "~> 3.0"
|
36
|
-
spec.add_runtime_dependency "uri", ">= 0.12.0"
|
36
|
+
spec.add_runtime_dependency "uri", "~> 0.12", ">= 0.12.0"
|
37
37
|
end
|
metadata
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: linzer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Landaeta
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: openssl
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
17
20
|
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
22
|
version: 3.0.0
|
@@ -21,6 +24,9 @@ dependencies:
|
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
24
30
|
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
32
|
version: 3.0.0
|
@@ -76,6 +82,9 @@ dependencies:
|
|
76
82
|
name: uri
|
77
83
|
requirement: !ruby/object:Gem::Requirement
|
78
84
|
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0.12'
|
79
88
|
- - ">="
|
80
89
|
- !ruby/object:Gem::Version
|
81
90
|
version: 0.12.0
|
@@ -83,6 +92,9 @@ dependencies:
|
|
83
92
|
prerelease: false
|
84
93
|
version_requirements: !ruby/object:Gem::Requirement
|
85
94
|
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0.12'
|
86
98
|
- - ">="
|
87
99
|
- !ruby/object:Gem::Version
|
88
100
|
version: 0.12.0
|