File: aws_sigv4_util.rb

package info (click to toggle)
ruby-faraday-middleware-aws-sigv4 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 124 kB
  • sloc: ruby: 65; makefile: 4
file content (36 lines) | stat: -rw-r--r-- 784 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

module FaradayMiddleware
  module AwsSigV4Util
    def seahorse_encode_query(url)
      return url unless url.query

      params = URI.decode_www_form(url.query)

      if params.any? { |_, v| v["\s"] }
        url = url.dup
        url.query = seahorse_encode_www_form(params)
      end

      url
    end

    def seahorse_encode_www_form(params)
      params.flat_map do |key, value|
        encoded_key = URI.encode_www_form_component(key)

        if value.nil?
          encoded_key
        else
          Array(value).map do |v|
            if v.nil?
              # nothing to do
            else
              "#{encoded_key}=#{Aws::Sigv4::Signer.uri_escape(v)}"
            end
          end
        end
      end.join('&')
    end
  end
end