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