Class: ApiAuth::RequestDrivers::HttpRequest
- Inherits:
-
Object
- Object
- ApiAuth::RequestDrivers::HttpRequest
show all
- Includes:
- Helpers
- Defined in:
- lib/api_auth/request_drivers/http.rb
Overview
Instance Method Summary
collapse
Methods included from Helpers
#b64_encode, #capitalize_keys, #sha256_base64digest
Constructor Details
#initialize(request) ⇒ HttpRequest
Returns a new instance of HttpRequest.
6
7
8
|
# File 'lib/api_auth/request_drivers/http.rb', line 6
def initialize(request)
@request = request
end
|
Instance Method Details
61
62
63
|
# File 'lib/api_auth/request_drivers/http.rb', line 61
def
%w[Authorization AUTHORIZATION HTTP_AUTHORIZATION]
end
|
#body ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/api_auth/request_drivers/http.rb', line 65
def body
if body_source.respond_to?(:read)
result = body_source.read
body_source.rewind
result
else
body_source.to_s
end
end
|
#calculated_hash ⇒ Object
15
16
17
|
# File 'lib/api_auth/request_drivers/http.rb', line 15
def calculated_hash
sha256_base64digest(body)
end
|
#content_hash ⇒ Object
41
42
43
|
# File 'lib/api_auth/request_drivers/http.rb', line 41
def content_hash
(%w[X-AUTHORIZATION-CONTENT-SHA256])
end
|
#content_hash_mismatch? ⇒ Boolean
25
26
27
28
29
30
31
|
# File 'lib/api_auth/request_drivers/http.rb', line 25
def content_hash_mismatch?
if %w[POST PUT].include?(http_method)
calculated_hash != content_hash
else
false
end
end
|
#content_type ⇒ Object
37
38
39
|
# File 'lib/api_auth/request_drivers/http.rb', line 37
def content_type
(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE])
end
|
75
76
77
|
# File 'lib/api_auth/request_drivers/http.rb', line 75
def
capitalize_keys @request..to_h
end
|
#http_method ⇒ Object
33
34
35
|
# File 'lib/api_auth/request_drivers/http.rb', line 33
def http_method
@request.verb.to_s.upcase
end
|
#original_uri ⇒ Object
45
46
47
|
# File 'lib/api_auth/request_drivers/http.rb', line 45
def original_uri
(%w[X-ORIGINAL-URI X_ORIGINAL_URI HTTP_X_ORIGINAL_URI])
end
|
#populate_content_hash ⇒ Object
19
20
21
22
23
|
# File 'lib/api_auth/request_drivers/http.rb', line 19
def populate_content_hash
return unless %w[POST PUT].include?(http_method)
@request['X-Authorization-Content-SHA256'] = calculated_hash
end
|
#request_uri ⇒ Object
49
50
51
|
# File 'lib/api_auth/request_drivers/http.rb', line 49
def request_uri
@request.uri.request_uri
end
|
10
11
12
13
|
# File 'lib/api_auth/request_drivers/http.rb', line 10
def ()
@request['Authorization'] =
@request
end
|
#set_date ⇒ Object
53
54
55
|
# File 'lib/api_auth/request_drivers/http.rb', line 53
def set_date
@request['Date'] = Time.now.utc.httpdate
end
|
#timestamp ⇒ Object
57
58
59
|
# File 'lib/api_auth/request_drivers/http.rb', line 57
def timestamp
(%w[DATE HTTP_DATE])
end
|