Sha256: 3989c206232e18da0cccb645a2e3e0bfe824076e9bc405334906e04ecae12bf0

Contents?: true

Size: 1.64 KB

Versions: 35

Compression:

Stored size: 1.64 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 `unsignedPayload` and `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
              elsif unsigned_payload?(context.operation)
                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'] || payload.shape['streaming']
          else
            false
          end
        end

        def unsigned_payload?(operation)
          operation['unsignedPayload'] ||
            operation['authtype'] == 'v4-unsigned-body'
        end

        def requires_length?(ref)
          if (payload = ref[:payload_member])
            payload['requiresLength'] || payload.shape['requiresLength']
          else
            false
          end
        end

      end

      handler(Handler, step: :sign)

    end

  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
aws-sdk-core-3.220.2 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.220.1 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.220.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.219.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.218.1 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.218.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.217.1 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.217.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.216.1 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.216.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.215.1 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.215.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.214.1 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.214.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.213.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.212.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.211.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.210.0 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.209.1 lib/aws-sdk-core/plugins/transfer_encoding.rb
aws-sdk-core-3.209.0 lib/aws-sdk-core/plugins/transfer_encoding.rb