Class: ZeroClick::Sellers::Request
- Inherits:
-
Object
- Object
- ZeroClick::Sellers::Request
- Defined in:
- lib/zeroclick/sellers/contracts.rb
Overview
A framework-neutral view of an inbound request.
The SDK never loads Rails, Sinatra or Rack — everything flows through Request and Response, and each adapter does the (small) translation. That is what keeps one implementation serving every Ruby web framework.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#path_and_query ⇒ Object
readonly
Returns the value of attribute path_and_query.
Instance Method Summary collapse
- #header(name) ⇒ Object
-
#initialize(method:, path_and_query:, headers: {}, body: "") ⇒ Request
constructor
path_and_querymust be the RAW, percent-encoded path and query exactly as it arrived.
Constructor Details
#initialize(method:, path_and_query:, headers: {}, body: "") ⇒ Request
path_and_query must be the RAW, percent-encoded path and query exactly
as it arrived. Frameworks that hand you a decoded path will break
verification for any route containing an encoded character — see
Middleware.path_and_query_from_env.
body must be the raw bytes as received. Decode nothing before verifying.
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/zeroclick/sellers/contracts.rb', line 41 def initialize(method:, path_and_query:, headers: {}, body: "") unless body.is_a?(String) raise Error.new("malformed_input", operation: "Request", message: "body must be a String of raw bytes; decode nothing before verifying") end @method = method @path_and_query = path_and_query @headers = headers.each_with_object({}) { |(k, v), out| out[k.to_s.downcase] = v }.freeze # ASCII-8BIT so the SHA-256 below hashes bytes, never a re-encoding. @body = body.dup.force_encoding(Encoding::BINARY).freeze freeze end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
33 34 35 |
# File 'lib/zeroclick/sellers/contracts.rb', line 33 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
33 34 35 |
# File 'lib/zeroclick/sellers/contracts.rb', line 33 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
33 34 35 |
# File 'lib/zeroclick/sellers/contracts.rb', line 33 def method @method end |
#path_and_query ⇒ Object (readonly)
Returns the value of attribute path_and_query.
33 34 35 |
# File 'lib/zeroclick/sellers/contracts.rb', line 33 def path_and_query @path_and_query end |
Instance Method Details
#header(name) ⇒ Object
55 56 57 |
# File 'lib/zeroclick/sellers/contracts.rb', line 55 def header(name) @headers[name.to_s.downcase] end |