Class: ApiAuth::RequestDrivers::HttpRequest

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

Overview

:nodoc:

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

#authorization_headerObject


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

def authorization_header
  find_header %w[Authorization AUTHORIZATION HTTP_AUTHORIZATION]
end

#bodyObject


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_md5Object


15
16
17
# File 'lib/api_auth/request_drivers/http.rb', line 15

def calculated_md5
  md5_base64digest(body)
end

#content_md5Object


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

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

#content_typeObject


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

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

#http_methodObject


33
34
35
# File 'lib/api_auth/request_drivers/http.rb', line 33

def http_method
  @request.verb.to_s.upcase
end

#md5_mismatch?Boolean

Returns:

  • (Boolean)

25
26
27
28
29
30
31
# File 'lib/api_auth/request_drivers/http.rb', line 25

def md5_mismatch?
  if %w[POST PUT].include?(http_method)
    calculated_md5 != content_md5
  else
    false
  end
end

#original_uriObject


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

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

#populate_content_md5Object


19
20
21
22
23
# 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_uriObject


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

def request_uri
  @request.uri.request_uri
end

#set_auth_header(header) ⇒ Object


10
11
12
13
# File 'lib/api_auth/request_drivers/http.rb', line 10

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

#set_dateObject


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

def set_date
  @request['Date'] = Time.now.utc.httpdate
end

#timestampObject


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

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