linzer 0.7.5 → 0.7.7.beta1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0cb9025767ae44e70b7a9462fa9f587fb99c34080e6903efd5b1fdf505c8ae98
4
- data.tar.gz: 2df4758cb77e19d255fcc1e135a1f67a4f5203cdc8cef2535ae148c7a3f0901a
3
+ metadata.gz: 4a0c6679a12f4d81ad0c404c0250e968540434ef2ea973c0d15efc946b337ec8
4
+ data.tar.gz: e6ab100316577c1f5b4c0b407ba6a23bb9815dc944f0cbd88d664f86a1601ae9
5
5
  SHA512:
6
- metadata.gz: 7f5807077e46c27db08d764f0b696421bbf61cd04b0906ce6d14d547a22149cfbf8a7496559d363a73fa4ee1d7e0b8e5e9187ed84dd0d491a6fec59f8fd673fa
7
- data.tar.gz: 491a60772d4eb2da91c0ac9b1bb3dce27d61538c43a1ac78b28a804e0344a8f265f5ccc5a444b9a34391300513a289f8e9d4f194550683f8295a9d8fe5e82569
6
+ metadata.gz: 4c90ad154c524fe517baf299cae1071b890071db735c2ea5f029f5c471f7cc652ce301675d7a20223dad3b18b923f60bdd9cfb1c5ed4e5896f06fa66e37ad3cf
7
+ data.tar.gz: 3503fb59e52628fcb2df866045b95731b823a0e31df79e07e419e088f19707a42b6f36d8cccb1e6c8e20cc5f071dc16e5de986b2a5927c208a26ffff82cb5538
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.7.7.beta1] - 2025-07-07
4
+
5
+ - Introduce generic adapters for typical requests and responses.
6
+ This allows adapter classes to stop inheriting functionality from totally
7
+ unrelated implementations by relying on a saner hierarchy class.
8
+
9
+ ## [0.7.6] - 2025-07-03
10
+
11
+ - Fix a bug in the `Linzer::Message::Adapter::HTTPGem::Response` class where
12
+ the serialized id of fields like derived `@status` were not recognized.
13
+ This issue caused signature creation and verification to fail for `HTTP::Response`
14
+ instances. (Issue [#16](https://github.com/nomadium/linzer/issues/16))
15
+
3
16
  ## [0.7.5] - 2025-06-30
4
17
 
5
18
  - No changes since 0.7.4.
@@ -16,8 +16,6 @@ module Linzer
16
16
  self.class.to_s.include?("Response")
17
17
  end
18
18
 
19
- # XXX: attached request as specified in RFC has to be tested for Net::HTTP classes
20
- # and custom HTTP message classes
21
19
  def attached_request?
22
20
  response? && !!@attached_request
23
21
  end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cgi"
4
+
5
+ module Linzer
6
+ class Message
7
+ module Adapter
8
+ module Generic
9
+ class Request < Abstract
10
+ def initialize(operation, **options)
11
+ @operation = operation
12
+ freeze
13
+ end
14
+
15
+ def header(name)
16
+ @operation[name]
17
+ end
18
+
19
+ def attach!(signature)
20
+ signature.to_h.each { |h, v| @operation[h] = v }
21
+ @operation
22
+ end
23
+
24
+ private
25
+
26
+ def derived(name)
27
+ unimplemented_method = 'Derived field "@method" lookup is not implemented!'
28
+ case name.value
29
+ when "@method" then raise Error, unimplemented_method
30
+ when "@target-uri" then @operation.uri.to_s
31
+ when "@authority" then @operation.uri.authority.downcase
32
+ when "@scheme" then @operation.uri.scheme.downcase
33
+ when "@request-target" then @operation.uri.request_uri
34
+ when "@path" then @operation.uri.path
35
+ when "@query" then "?%s" % String(@operation.uri.query)
36
+ when "@query-param" then query_param(name)
37
+ end
38
+ end
39
+
40
+ def query_param(name)
41
+ param_name = name.parameters["name"]
42
+ return nil if !param_name
43
+ decoded_param_name = URI.decode_uri_component(param_name)
44
+ params = CGI.parse(@operation.uri.query)
45
+ URI.encode_uri_component(params[decoded_param_name]&.first)
46
+ end
47
+
48
+ def field(name)
49
+ has_tr = name.parameters["tr"]
50
+ return nil if has_tr # HTTP requests don't have trailer fields
51
+ value = @operation[name.value.to_s]
52
+ value.dup&.strip
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Linzer
4
+ class Message
5
+ module Adapter
6
+ module Generic
7
+ class Response < Abstract
8
+ def initialize(operation, **options)
9
+ @operation = operation
10
+ attached_request = options[:attached_request]
11
+ @attached_request = attached_request ? Message.new(attached_request) : nil
12
+ validate_attached_request @attached_request if @attached_request
13
+ freeze
14
+ end
15
+
16
+ def header(name)
17
+ @operation[name]
18
+ end
19
+
20
+ def attach!(signature)
21
+ signature.to_h.each { |h, v| @operation[h] = v }
22
+ @operation
23
+ end
24
+
25
+ private
26
+
27
+ def derived(name)
28
+ raise Linzer::Error, "Sub-classes are required to implement this method!"
29
+ end
30
+
31
+ def field(name)
32
+ has_tr = name.parameters["tr"]
33
+ return nil if has_tr # is there a library actually supporting trailers?
34
+ value = @operation[name.value.to_s]
35
+ value.dup&.strip
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -4,11 +4,7 @@ module Linzer
4
4
  class Message
5
5
  module Adapter
6
6
  module HTTPGem
7
- class Request < Linzer::Message::Adapter::NetHTTP::Request
8
- def header(name)
9
- @operation[name]
10
- end
11
-
7
+ class Request < Generic::Request
12
8
  private
13
9
 
14
10
  def derived(name)
@@ -1,32 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Example HTTP message adapter for HTTP::Response class from http ruby gem.
3
+ # HTTP message adapter for HTTP::Response class from http ruby gem.
4
4
  # https://github.com/httprb/http
5
- # It's not required automatically to avoid making http gem a dependency.
5
+ #
6
+ # It's not loaded automatically to avoid making http gem a dependency.
6
7
  #
7
8
  module Linzer
8
9
  class Message
9
10
  module Adapter
10
11
  module HTTPGem
11
- class Response < Abstract
12
- def initialize(operation, **options)
13
- @operation = operation
14
- freeze
15
- end
16
-
17
- def header(name)
18
- @operation[name]
19
- end
20
-
21
- # XXX: this implementation is incomplete, e.g.: ;tr parameter is not supported yet
22
- def [](field_name)
23
- return @operation.code if field_name == "@status"
24
- @operation[field_name]
25
- end
12
+ class Response < Generic::Response
13
+ private
26
14
 
27
- def attach!(signature)
28
- signature.to_h.each { |h, v| @operation[h] = v }
29
- @operation
15
+ def derived(name)
16
+ case name.value
17
+ when "@status" then @operation.status.to_i
18
+ end
30
19
  end
31
20
  end
32
21
  end
@@ -1,54 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "cgi"
4
-
5
3
  module Linzer
6
4
  class Message
7
5
  module Adapter
8
6
  module NetHTTP
9
- class Request < Abstract
10
- def initialize(operation, **options)
11
- @operation = operation
12
- freeze
13
- end
14
-
15
- def header(name)
16
- @operation[name]
17
- end
18
-
19
- def attach!(signature)
20
- signature.to_h.each { |h, v| @operation[h] = v }
21
- @operation
22
- end
23
-
7
+ class Request < Generic::Request
24
8
  private
25
9
 
26
10
  def derived(name)
27
- case name.value
28
- when "@method" then @operation.method
29
- when "@target-uri" then @operation.uri.to_s
30
- when "@authority" then @operation.uri.authority.downcase
31
- when "@scheme" then @operation.uri.scheme.downcase
32
- when "@request-target" then @operation.uri.request_uri
33
- when "@path" then @operation.uri.path
34
- when "@query" then "?%s" % String(@operation.uri.query)
35
- when "@query-param" then query_param(name)
36
- end
37
- end
38
-
39
- def query_param(name)
40
- param_name = name.parameters["name"]
41
- return nil if !param_name
42
- decoded_param_name = URI.decode_uri_component(param_name)
43
- params = CGI.parse(@operation.uri.query)
44
- URI.encode_uri_component(params[decoded_param_name]&.first)
45
- end
46
-
47
- def field(name)
48
- has_tr = name.parameters["tr"]
49
- return nil if has_tr # HTTP requests don't have trailer fields
50
- value = @operation[name.value.to_s]
51
- value.dup&.strip
11
+ return @operation.method if name.value == "@method"
12
+ super
52
13
  end
53
14
  end
54
15
  end
@@ -4,24 +4,7 @@ module Linzer
4
4
  class Message
5
5
  module Adapter
6
6
  module NetHTTP
7
- class Response < Abstract
8
- def initialize(operation, **options)
9
- @operation = operation
10
- attached_request = options[:attached_request]
11
- @attached_request = attached_request ? Message.new(attached_request) : nil
12
- validate_attached_request @attached_request if @attached_request
13
- freeze
14
- end
15
-
16
- def header(name)
17
- @operation[name]
18
- end
19
-
20
- def attach!(signature)
21
- signature.to_h.each { |h, v| @operation[h] = v }
22
- @operation
23
- end
24
-
7
+ class Response < Generic::Response
25
8
  private
26
9
 
27
10
  def derived(name)
@@ -29,14 +12,6 @@ module Linzer
29
12
  when "@status" then @operation.code.to_i
30
13
  end
31
14
  end
32
-
33
- # XXX: this implementation is incomplete, e.g.: ;bs parameter is not supported yet
34
- def field(name)
35
- has_tr = name.parameters["tr"]
36
- return nil if has_tr # Net::HTTP doesn't support trailers
37
- value = @operation[name.value.to_s]
38
- value.dup&.strip
39
- end
40
15
  end
41
16
  end
42
17
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "adapter/abstract"
4
+ require_relative "adapter/generic/request"
5
+ require_relative "adapter/generic/response"
4
6
  require_relative "adapter/rack/common"
5
7
  require_relative "adapter/rack/request"
6
8
  require_relative "adapter/rack/response"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Linzer
4
- VERSION = "0.7.5"
4
+ VERSION = "0.7.7.beta1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.7.7.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Landaeta
@@ -203,6 +203,8 @@ files:
203
203
  - lib/linzer/message.rb
204
204
  - lib/linzer/message/adapter.rb
205
205
  - lib/linzer/message/adapter/abstract.rb
206
+ - lib/linzer/message/adapter/generic/request.rb
207
+ - lib/linzer/message/adapter/generic/response.rb
206
208
  - lib/linzer/message/adapter/http_gem/request.rb
207
209
  - lib/linzer/message/adapter/http_gem/response.rb
208
210
  - lib/linzer/message/adapter/net_http/request.rb