Class: Shmac::Request
- Inherits:
-
Object
- Object
- Shmac::Request
- Defined in:
- lib/shmac/request.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #authorization ⇒ Object
- #content_md5 ⇒ Object
- #content_md5_matches_body? ⇒ Boolean
-
#date(namespace = nil) ⇒ Object
Prefer the value of a namespaced date key if present.
-
#initialize(path:, method:, headers:, body: nil, content_type: nil) ⇒ Request
constructor
A new instance of Request.
- #tampered_body? ⇒ Boolean
Constructor Details
#initialize(path:, method:, headers:, body: nil, content_type: nil) ⇒ Request
Returns a new instance of Request.
8 9 10 11 12 13 14 |
# File 'lib/shmac/request.rb', line 8 def initialize path:, method:, headers:, body: nil, content_type: nil @path = path @method = method self.headers = headers @body = body @content_type = content_type end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
6 7 8 |
# File 'lib/shmac/request.rb', line 6 def body @body end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
6 7 8 |
# File 'lib/shmac/request.rb', line 6 def content_type @content_type end |
#headers ⇒ Object
Returns the value of attribute headers.
6 7 8 |
# File 'lib/shmac/request.rb', line 6 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
6 7 8 |
# File 'lib/shmac/request.rb', line 6 def method @method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/shmac/request.rb', line 6 def path @path end |
Instance Method Details
#authorization ⇒ Object
39 40 41 42 |
# File 'lib/shmac/request.rb', line 39 def # Test for x-authorization for clients that have issues with standard headers headers.fetch("x-authorization") { headers["authorization"] } end |
#content_md5 ⇒ Object
23 24 25 26 |
# File 'lib/shmac/request.rb', line 23 def content_md5 # Fallback to x-content-md5 for clients that have issues with standard headers headers.fetch("content-md5") { headers["x-content-md5"] } end |
#content_md5_matches_body? ⇒ Boolean
35 36 37 |
# File 'lib/shmac/request.rb', line 35 def content_md5_matches_body? Security.secure_compare content_md5, Digest::MD5.base64digest(body) end |
#date(namespace = nil) ⇒ Object
Prefer the value of a namespaced date key if present
17 18 19 20 21 |
# File 'lib/shmac/request.rb', line 17 def date namespace = nil date_key = [namespace, "date"].compact.join("-").downcase headers.fetch(date_key) { headers["date"] } end |
#tampered_body? ⇒ Boolean
28 29 30 31 32 33 |
# File 'lib/shmac/request.rb', line 28 def tampered_body? return false unless body return false if content_md5.to_s.strip.empty? !content_md5_matches_body? end |