Class: ApiAuth::RequestDrivers::NetHttpRequest
- Inherits:
-
Object
- Object
- ApiAuth::RequestDrivers::NetHttpRequest
show all
- Includes:
- Helpers
- Defined in:
- lib/api_auth/request_drivers/net_http.rb
Overview
Instance Method Summary
collapse
Methods included from Helpers
#b64_encode, #capitalize_keys, #sha256_base64digest
Constructor Details
Returns a new instance of NetHttpRequest.
6
7
8
9
10
|
# File 'lib/api_auth/request_drivers/net_http.rb', line 6
def initialize(request)
@request = request
@headers =
true
end
|
Instance Method Details
75
76
77
|
# File 'lib/api_auth/request_drivers/net_http.rb', line 75
def
%w[Authorization AUTHORIZATION HTTP_AUTHORIZATION]
end
|
#calculated_hash ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/api_auth/request_drivers/net_http.rb', line 18
def calculated_hash
if @request.respond_to?(:body_stream) && @request.body_stream
body = @request.body_stream.read
@request.body_stream.rewind
else
body = @request.body
end
sha256_base64digest(body || '')
end
|
#content_hash ⇒ Object
55
56
57
|
# File 'lib/api_auth/request_drivers/net_http.rb', line 55
def content_hash
(%w[X-Authorization-Content-SHA256])
end
|
#content_hash_mismatch? ⇒ Boolean
35
36
37
38
39
40
41
|
# File 'lib/api_auth/request_drivers/net_http.rb', line 35
def content_hash_mismatch?
if @request.class::REQUEST_HAS_BODY
calculated_hash != content_hash
else
false
end
end
|
#content_type ⇒ Object
51
52
53
|
# File 'lib/api_auth/request_drivers/net_http.rb', line 51
def content_type
(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE])
end
|
43
44
45
|
# File 'lib/api_auth/request_drivers/net_http.rb', line 43
def
@request
end
|
#http_method ⇒ Object
47
48
49
|
# File 'lib/api_auth/request_drivers/net_http.rb', line 47
def http_method
@request.method.upcase
end
|
#original_uri ⇒ Object
59
60
61
|
# File 'lib/api_auth/request_drivers/net_http.rb', line 59
def original_uri
(%w[X-ORIGINAL-URI X_ORIGINAL_URI HTTP_X_ORIGINAL_URI])
end
|
#populate_content_hash ⇒ Object
29
30
31
32
33
|
# File 'lib/api_auth/request_drivers/net_http.rb', line 29
def populate_content_hash
return unless @request.class::REQUEST_HAS_BODY
@request['X-Authorization-Content-SHA256'] = calculated_hash
end
|
#request_uri ⇒ Object
63
64
65
|
# File 'lib/api_auth/request_drivers/net_http.rb', line 63
def request_uri
@request.path
end
|
12
13
14
15
16
|
# File 'lib/api_auth/request_drivers/net_http.rb', line 12
def ()
@request['Authorization'] =
@headers =
@request
end
|
#set_date ⇒ Object
67
68
69
|
# File 'lib/api_auth/request_drivers/net_http.rb', line 67
def set_date
@request['DATE'] = Time.now.utc.httpdate
end
|
#timestamp ⇒ Object
71
72
73
|
# File 'lib/api_auth/request_drivers/net_http.rb', line 71
def timestamp
(%w[DATE HTTP_DATE])
end
|