Class: Linzer::Message
- Inherits:
-
Object
- Object
- Linzer::Message
- Extended by:
- Forwardable
- Defined in:
- lib/linzer/message.rb,
lib/linzer/message/field.rb,
lib/linzer/message/adapter.rb,
lib/linzer/message/wrapper.rb,
lib/linzer/message/field/parser.rb,
lib/linzer/message/adapter/abstract.rb,
lib/linzer/message/adapter/rack/common.rb,
lib/linzer/message/adapter/rack/request.rb,
lib/linzer/message/adapter/rack/response.rb,
lib/linzer/message/adapter/generic/request.rb,
lib/linzer/message/adapter/generic/response.rb,
lib/linzer/message/adapter/http_gem/request.rb,
lib/linzer/message/adapter/net_http/request.rb,
lib/linzer/message/adapter/http_gem/response.rb,
lib/linzer/message/adapter/net_http/response.rb
Overview
Wraps an HTTP request or response for signing and verification.
Message provides a unified interface for accessing HTTP message components regardless of the underlying HTTP library (Rack, Net::HTTP, http.rb, etc.). It handles the extraction of both regular header fields and derived components (like ‘@method`, `@path`, `@authority`).
Defined Under Namespace
Modules: Adapter, Wrapper Classes: Field
Class Method Summary collapse
-
.register_adapter(operation_class, adapter_class) ⇒ Object
Registers a custom adapter for an HTTP message class.
Instance Method Summary collapse
-
#[](component) ⇒ String, ...
Retrieves a component value from the message.
-
#attach!(signature) ⇒ Object
Attaches a signature to the underlying HTTP message.
-
#attached_request? ⇒ Boolean
Checks if this response message has an attached request.
-
#field?(component) ⇒ Boolean
Checks if a component exists in the message.
-
#header(name) ⇒ String?
Retrieves a header value by name.
-
#initialize(operation, attached_request: nil) ⇒ Message
constructor
Creates a new Message wrapper.
-
#request? ⇒ Boolean
Checks if this message wraps an HTTP request.
-
#response? ⇒ Boolean
Checks if this message wraps an HTTP response.
Constructor Details
#initialize(operation, attached_request: nil) ⇒ Message
Creates a new Message wrapper.
52 53 54 55 |
# File 'lib/linzer/message.rb', line 52 def initialize(operation, attached_request: nil) @adapter = Wrapper.wrap(operation, attached_request: attached_request) freeze end |
Class Method Details
.register_adapter(operation_class, adapter_class) ⇒ Object
Registers a custom adapter for an HTTP message class.
Use this to add support for HTTP libraries not built into Linzer. The adapter class must inherit from Linzer::Message::Adapter::Abstract and implement the required interface.
134 135 136 |
# File 'lib/linzer/message.rb', line 134 def register_adapter(operation_class, adapter_class) Wrapper.register_adapter(operation_class, adapter_class) end |
Instance Method Details
#[](component) ⇒ String, ...
Retrieves a component value from the message.
Supports both regular header fields and derived components:
-
Header fields: ‘“content-type”`, `“date”`, `“x-custom-header”`
-
Derived components: ‘“@method”`, `“@path”`, `“@authority”`, `“@status”`
-
With parameters: ‘“content-type”;bs`, `“example-dict”;key=“a”`, `“date”;req`
100 |
# File 'lib/linzer/message.rb', line 100 def_delegators :@adapter, :header, :field?, :[] |
#attach!(signature) ⇒ Object
Attaches a signature to the underlying HTTP message.
Modifies the original HTTP message by adding the signature and signature-input headers from the signature.
114 |
# File 'lib/linzer/message.rb', line 114 def_delegators :@adapter, :attach! |
#attached_request? ⇒ Boolean
Checks if this response message has an attached request.
68 |
# File 'lib/linzer/message.rb', line 68 def_delegators :@adapter, :request?, :response?, :attached_request? |
#field?(component) ⇒ Boolean
Checks if a component exists in the message.
|
|
# File 'lib/linzer/message.rb', line 75
|
#header(name) ⇒ String?
Retrieves a header value by name.
|
|
# File 'lib/linzer/message.rb', line 70
|
#request? ⇒ Boolean
Checks if this message wraps an HTTP request.
|
|
# File 'lib/linzer/message.rb', line 57
|
#response? ⇒ Boolean
Checks if this message wraps an HTTP response.
|
|
# File 'lib/linzer/message.rb', line 61
|