module HTTPX::Plugins::AWSSigV4::RequestMethods

  1. lib/httpx/plugins/aws_sigv4.rb

Methods

Public Instance

  1. canonical_path
  2. canonical_query

Public Instance methods

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