lib/api_auth/headers.rb in api-auth-1.3.2 vs lib/api_auth/headers.rb in api-auth-1.4.0
- old
+ new
@@ -50,18 +50,36 @@
def timestamp
@request.timestamp
end
# Returns the canonical string computed from the request's headers
- def canonical_string
+ def canonical_string_without_http_method
[ @request.content_type,
@request.content_md5,
- parse_uri(@request.request_uri),
+ parse_uri(@request.request_uri),
@request.timestamp
].join(",")
end
+ # temp backwards compatibility
+ alias_method :canonical_string, :canonical_string_without_http_method
+
+ def canonical_string_with_http_method(override_method = nil)
+ request_method = override_method || @request.http_method
+
+ if request_method.nil?
+ raise ArgumentError, "unable to determine the http method from the request, please supply an override"
+ end
+
+ [ request_method.upcase,
+ @request.content_type,
+ @request.content_md5,
+ parse_uri(@request.request_uri),
+ @request.timestamp
+ ].join(",")
+ end
+
# Returns the authorization header from the request's headers
def authorization_header
@request.authorization_header
end
@@ -90,11 +108,13 @@
@request.set_auth_header header
end
private
+ URI_WITHOUT_HOST_REGEXP = %r{https?://[^,?/]*}
+
def parse_uri(uri)
- uri_without_host = uri.gsub(/https?:\/\/[^(,|\?|\/)]*/, '')
+ uri_without_host = uri.gsub(URI_WITHOUT_HOST_REGEXP, '')
return '/' if uri_without_host.empty?
uri_without_host
end
end
end