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, #md5_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
60
61
62
|
# File 'lib/api_auth/request_drivers/http.rb', line 60
def
%w[Authorization AUTHORIZATION HTTP_AUTHORIZATION]
end
|
#body ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'lib/api_auth/request_drivers/http.rb', line 64
def body
if body_source.respond_to?(:read)
result = body_source.read
body_source.rewind
result
else
body_source.to_s
end
end
|
#calculated_md5 ⇒ Object
15
16
17
|
# File 'lib/api_auth/request_drivers/http.rb', line 15
def calculated_md5
md5_base64digest(body)
end
|
#content_md5 ⇒ Object
40
41
42
|
# File 'lib/api_auth/request_drivers/http.rb', line 40
def content_md5
(%w[CONTENT-MD5 CONTENT_MD5])
end
|
#content_type ⇒ Object
36
37
38
|
# File 'lib/api_auth/request_drivers/http.rb', line 36
def content_type
(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE])
end
|
#http_method ⇒ Object
32
33
34
|
# File 'lib/api_auth/request_drivers/http.rb', line 32
def http_method
@request.verb.to_s.upcase
end
|
#md5_mismatch? ⇒ Boolean
24
25
26
27
28
29
30
|
# File 'lib/api_auth/request_drivers/http.rb', line 24
def md5_mismatch?
if %w[POST PUT].include?(http_method)
calculated_md5 != content_md5
else
false
end
end
|
#original_uri ⇒ Object
44
45
46
|
# File 'lib/api_auth/request_drivers/http.rb', line 44
def original_uri
(%w[X-ORIGINAL-URI X_ORIGINAL_URI HTTP_X_ORIGINAL_URI])
end
|
#populate_content_md5 ⇒ Object
19
20
21
22
|
# File 'lib/api_auth/request_drivers/http.rb', line 19
def populate_content_md5
return unless %w[POST PUT].include?(http_method)
@request['Content-MD5'] = calculated_md5
end
|
#request_uri ⇒ Object
48
49
50
|
# File 'lib/api_auth/request_drivers/http.rb', line 48
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
52
53
54
|
# File 'lib/api_auth/request_drivers/http.rb', line 52
def set_date
@request['Date'] = Time.now.utc.httpdate
end
|
#timestamp ⇒ Object
56
57
58
|
# File 'lib/api_auth/request_drivers/http.rb', line 56
def timestamp
(%w[DATE HTTP_DATE])
end
|