Module: HTTPX::Plugins::AWSSigV4::RequestMethods
- Defined in:
- lib/httpx/plugins/aws_sigv4.rb
Instance Method Summary collapse
Instance Method Details
#canonical_path ⇒ Object
198 199 200 201 202 |
# File 'lib/httpx/plugins/aws_sigv4.rb', line 198 def canonical_path path = uri.path.dup path << "/" if path.empty? path.gsub(%r{[^/]+}) { |part| CGI.escape(part.encode("UTF-8")).gsub("+", "%20").gsub("%7E", "~") } end |
#canonical_query ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/httpx/plugins/aws_sigv4.rb', line 204 def canonical_query params = query.split("&") # params = params.map { |p| p.match(/=/) ? p : p + '=' } # From: https://docs.aws.amazon.com/IAM/latest/UserGuide/create-signed-request.html#create-canonical-request # Sort the parameter names by character code point in ascending order. # Parameters with duplicate names should be sorted by value. # # Default sort <=> in JRuby will swap members # occasionally when <=> is 0 (considered still sorted), but this # causes our normalized query string to not match the sent querystring. # When names match, we then sort by their values. When values also # match then we sort by their original order params.each.with_index.sort do |a, b| a, a_offset = a b, b_offset = b a_name, a_value = a.split("=", 2) b_name, b_value = b.split("=", 2) if a_name == b_name if a_value == b_value a_offset <=> b_offset else a_value <=> b_value end else a_name <=> b_name end end.map(&:first).join("&") end |