Class: ApiAuth::RequestDrivers::HttpiRequest

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/api_auth/request_drivers/httpi.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from Helpers

#b64_encode, #capitalize_keys, #md5_base64digest

Constructor Details

#initialize(request) ⇒ HttpiRequest

Returns a new instance of HttpiRequest.


6
7
8
9
10
# File 'lib/api_auth/request_drivers/httpi.rb', line 6

def initialize(request)
  @request = request
  fetch_headers
  true
end

Instance Method Details

#authorization_headerObject


70
71
72
# File 'lib/api_auth/request_drivers/httpi.rb', line 70

def authorization_header
  find_header %w[Authorization AUTHORIZATION HTTP_AUTHORIZATION]
end

#calculated_md5Object


18
19
20
# File 'lib/api_auth/request_drivers/httpi.rb', line 18

def calculated_md5
  md5_base64digest(@request.body || '')
end

#content_md5Object


49
50
51
# File 'lib/api_auth/request_drivers/httpi.rb', line 49

def content_md5
  find_header(%w[CONTENT-MD5 CONTENT_MD5])
end

#content_typeObject


45
46
47
# File 'lib/api_auth/request_drivers/httpi.rb', line 45

def content_type
  find_header(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE])
end

#fetch_headersObject


37
38
39
# File 'lib/api_auth/request_drivers/httpi.rb', line 37

def fetch_headers
  @headers = capitalize_keys @request.headers
end

#http_methodObject


41
42
43
# File 'lib/api_auth/request_drivers/httpi.rb', line 41

def http_method
  nil # not possible to get the method at this layer
end

#md5_mismatch?Boolean

Returns:

  • (Boolean)

29
30
31
32
33
34
35
# File 'lib/api_auth/request_drivers/httpi.rb', line 29

def md5_mismatch?
  if @request.body
    calculated_md5 != content_md5
  else
    false
  end
end

#original_uriObject


53
54
55
# File 'lib/api_auth/request_drivers/httpi.rb', line 53

def original_uri
  find_header(%w[X-ORIGINAL-URI X_ORIGINAL_URI HTTP_X_ORIGINAL_URI])
end

#populate_content_md5Object


22
23
24
25
26
27
# File 'lib/api_auth/request_drivers/httpi.rb', line 22

def populate_content_md5
  return unless @request.body

  @request.headers['Content-MD5'] = calculated_md5
  fetch_headers
end

#request_uriObject


57
58
59
# File 'lib/api_auth/request_drivers/httpi.rb', line 57

def request_uri
  @request.url.request_uri
end

#set_auth_header(header) ⇒ Object


12
13
14
15
16
# File 'lib/api_auth/request_drivers/httpi.rb', line 12

def set_auth_header(header)
  @request.headers['Authorization'] = header
  fetch_headers
  @request
end

#set_dateObject


61
62
63
64
# File 'lib/api_auth/request_drivers/httpi.rb', line 61

def set_date
  @request.headers['DATE'] = Time.now.utc.httpdate
  fetch_headers
end

#timestampObject


66
67
68
# File 'lib/api_auth/request_drivers/httpi.rb', line 66

def timestamp
  find_header(%w[DATE HTTP_DATE])
end