Sha256: d35473d52bcd4cb9b7dbf8454096b263d6be01d78484bcc02c5673a42403ac0c
Contents?: true
Size: 1.64 KB
Versions: 2
Compression:
Stored size: 1.64 KB
Contents
# frozen_string_literal: true module Aws module Rest # NOTE: headers could be already populated if specified on input shape class ContentTypeHandler < Seahorse::Client::Handler def call(context) body = context.http_request.body if (payload = context.operation.input[:payload_member]) case payload.shape when Seahorse::Model::Shapes::BlobShape context.http_request.headers['Content-Type'] ||= 'application/octet-stream' when Seahorse::Model::Shapes::StringShape context.http_request.headers['Content-Type'] ||= 'text/plain' else apply_default_content_type(context) end elsif !body.respond_to?(:size) || non_empty_body?(body) apply_default_content_type(context) end @handler.call(context) end private def non_empty_body?(body) body.respond_to?(:size) && body.size.positive? end # content-type defaults as noted here: # rest-json: https://smithy.io/2.0/aws/protocols/aws-restxml-protocol.html#content-type # rest-xml: https://smithy.io/2.0/aws/protocols/aws-restxml-protocol.html#content-type def apply_default_content_type(context) protocol = context.config.api.metadata['protocol'] case protocol when 'rest-json' context.http_request.headers['Content-Type'] ||= 'application/json' when 'rest-xml' context.http_request.headers['Content-Type'] ||= 'application/xml' else raise "Unsupported protocol #{protocol}" end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
aws-sdk-core-3.192.1 | lib/aws-sdk-core/rest/request/content_type.rb |
aws-sdk-core-3.192.0 | lib/aws-sdk-core/rest/request/content_type.rb |