class Shmac::Request

Attributes

body[R]
content_type[R]
headers[R]
method[R]
path[R]

Public Class Methods

new(path:, method:, headers:, body: nil, content_type: nil) click to toggle source
# 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

Public Instance Methods

authorization() click to toggle source
# File lib/shmac/request.rb, line 39
def authorization
  # Test for x-authorization for clients that have issues with standard headers
  headers.fetch("x-authorization") { headers["authorization"] }
end
content_md5() click to toggle source
# 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?() click to toggle source
# 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) click to toggle source

Prefer the value of a namespaced date key if present

# 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
headers=(headers) click to toggle source
# File lib/shmac/request.rb, line 44
def headers= headers
  @headers = NormalizedHttpHeaders.new(headers).to_h
end
tampered_body?() click to toggle source
# 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