Sha256: 2390e29e9aeaa4812b2d9820158fe2d22e4d3b616428fa30f3edbd2e566acadc

Contents?: true

Size: 1.03 KB

Versions: 153

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Seahorse
  module Client
    module Plugins
      class ContentLength < Plugin

        # @api private
        class Handler < Client::Handler
          # https://github.com/ruby/net-http/blob/master/lib/net/http/requests.rb
          # Methods without body are forwards compatible, because content-length
          # may be set for requests without body but is technically incorrect.
          METHODS_WITHOUT_BODY = Set.new(
            %w[GET HEAD DELETE OPTIONS TRACE COPY MOVE]
          )

          def call(context)
            body = context.http_request.body
            method = context.http_request.http_method
            # We use Net::HTTP with body_stream which doesn't do this by default
            if body.respond_to?(:size) && !METHODS_WITHOUT_BODY.include?(method)
              context.http_request.headers['Content-Length'] = body.size
            end
            @handler.call(context)
          end
        end

        handler(Handler, step: :sign, priority: 0)

      end
    end
  end
end

Version data entries

153 entries across 153 versions & 1 rubygems

Version Path
aws-sdk-core-3.214.0 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.213.0 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.212.0 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.211.0 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.210.0 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.209.1 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.209.0 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.208.0 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.207.0 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.206.0 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.205.0 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.204.0 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.203.0 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.202.2 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.202.1 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.202.0 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.201.5 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.201.4 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.201.3 lib/seahorse/client/plugins/content_length.rb
aws-sdk-core-3.201.2 lib/seahorse/client/plugins/content_length.rb