Sha256: d443a384429ea21d76939d604baf8ee70197f5edf897834f3bec080a1618b9e2

Contents?: true

Size: 1.47 KB

Versions: 18

Compression:

Stored size: 1.47 KB

Contents

module Aws
  module Plugins

    # For Streaming Input Operations, when `requiresLength` is enabled
    # checking whether `Content-Length` header can be set,
    # for `v4-unsigned-body` operations, set `Transfer-Encoding` header
    class TransferEncoding < Seahorse::Client::Plugin

      # @api private
      class Handler < Seahorse::Client::Handler
        def call(context)
          if streaming?(context.operation.input)
            # If it's an IO object and not a File / String / String IO
            unless context.http_request.body.respond_to?(:size)
              if requires_length?(context.operation.input)
                # if size of the IO is not available but required
                raise Aws::Errors::MissingContentLength.new
              elsif context.operation['authtype'] == "v4-unsigned-body"
                context.http_request.headers['Transfer-Encoding'] = 'chunked'
              end
            end
          end

          @handler.call(context)
        end

        private

        def streaming?(ref)
          if payload = ref[:payload_member]
            payload["streaming"] || # checking ref and shape
              payload.shape["streaming"]
          else
            false
          end
        end

        def requires_length?(ref)
          payload = ref[:payload_member]
          payload["requiresLength"] || # checking ref and shape
            payload.shape["requiresLength"]
        end

      end

      handler(Handler, step: :sign)

    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
aws-sdk-core-3.100.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.99.2 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.99.1 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.99.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.98.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.97.1 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.97.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.96.1 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.96.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.95.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.94.1 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.94.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.93.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.92.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.91.1 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.91.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.90.1 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.90.0 lib/aws-sdk-core/plugins/transfer_encoding.rb