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