Class: ApiAuth::RequestDrivers::NetHttpRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/api_auth/request_drivers/net_http.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ NetHttpRequest

Returns a new instance of NetHttpRequest.


7
8
9
10
11
# File 'lib/api_auth/request_drivers/net_http.rb', line 7

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

Instance Method Details

#authorization_headerObject


64
65
66
# File 'lib/api_auth/request_drivers/net_http.rb', line 64

def authorization_header
  find_header %w(Authorization AUTHORIZATION HTTP_AUTHORIZATION)
end

#calculated_md5Object


19
20
21
# File 'lib/api_auth/request_drivers/net_http.rb', line 19

def calculated_md5
  Digest::MD5.base64digest(@request.body || '')
end

#content_md5Object


46
47
48
49
# File 'lib/api_auth/request_drivers/net_http.rb', line 46

def content_md5
  value = find_header(%w(CONTENT-MD5 CONTENT_MD5))
  value.nil? ? "" : value
end

#content_typeObject


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

def content_type
  value = find_header(%w(CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE))
  value.nil? ? "" : value
end

#fetch_headersObject


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

def fetch_headers
  @request
end

#md5_mismatch?Boolean

Returns:

  • (Boolean)

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

def md5_mismatch?
  if @request.class::REQUEST_HAS_BODY
    calculated_md5 != content_md5
  else
    false
  end
end

#populate_content_md5Object


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

def populate_content_md5
  if @request.class::REQUEST_HAS_BODY
    @request["Content-MD5"] = calculated_md5
  end
end

#request_uriObject


51
52
53
# File 'lib/api_auth/request_drivers/net_http.rb', line 51

def request_uri
  @request.path
end

#set_auth_header(header) ⇒ Object


13
14
15
16
17
# File 'lib/api_auth/request_drivers/net_http.rb', line 13

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

#set_dateObject


55
56
57
# File 'lib/api_auth/request_drivers/net_http.rb', line 55

def set_date
  @request["DATE"] = Time.now.utc.httpdate
end

#timestampObject


59
60
61
62
# File 'lib/api_auth/request_drivers/net_http.rb', line 59

def timestamp
  value = find_header(%w(DATE HTTP_DATE))
  value.nil? ? "" : value
end