Sha256: 094cb1a786b9562c06cea8e8a667fa07241fc40270e8866742ea1c17ae8a440c

Contents?: true

Size: 1.5 KB

Versions: 168

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

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

168 entries across 168 versions & 1 rubygems

Version Path
aws-sdk-core-3.200.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.199.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.198.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.197.2 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.197.1 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.197.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.194.1 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.194.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.193.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.192.1 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.192.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.191.6 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.191.5 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.191.4 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.191.3 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.191.2 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.191.1 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.191.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.190.3 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.190.2 lib/aws-sdk-core/plugins/transfer_encoding.rb