Sha256: 3c87b72976279175ec1a3d97b62953a24fb2905e9fe676cc767eb11a2024ccfe
Contents?: true
Size: 1.1 KB
Versions: 4
Compression:
Stored size: 1.1 KB
Contents
require 'aws-sdk-core' require 'faraday' class AwsV4Signer < Faraday::Middleware class Request def initialize(env) @env = env end def headers @env.request_headers end def set_header(header) @env.request_headers = header end def body @env.body || '' end def endpoint @env.url end def http_method @env.method.to_s.upcase end end def initialize(app, options = nil) super(app) credentials = options.fetch(:credentials) service_name = options.fetch(:service_name) region = options.fetch(:region) @signer = Aws::Signers::V4.new(credentials, service_name, region) @net_http = app.is_a?(Faraday::Adapter::NetHttp) end def call(env) normalize_for_net_http!(env) req = Request.new(env) @signer.sign(req) @app.call(env) end private def normalize_for_net_http!(env) return unless @net_http if Net::HTTP::HAVE_ZLIB env.request_headers['Accept-Encoding'] ||= 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3' end env.request_headers['Accept'] ||= '*/*' end end
Version data entries
4 entries across 4 versions & 1 rubygems