File: api_gateway.rb

package info (click to toggle)
ruby-aws-sdk-core 3.242.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 2,420 kB
  • sloc: ruby: 18,795; makefile: 4
file content (31 lines) | stat: -rw-r--r-- 884 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

module Aws
  module Plugins
    module Protocols
      class ApiGateway < Seahorse::Client::Plugin

        option(:protocol, 'api-gateway')

        class ContentTypeHandler < Seahorse::Client::Handler
          def call(context)
            body = context.http_request.body
            # Rest::Handler will set a default JSON body, so size can be checked
            # if this handler is run after serialization.
            if !body.respond_to?(:size) ||
               (body.respond_to?(:size) && body.size > 0)
               context.http_request.headers['Content-Type'] ||=
                 'application/json'
            end
            @handler.call(context)
          end
        end

        handler(Rest::Handler)
        handler(ContentTypeHandler, priority: 30)
        handler(Json::ErrorHandler, step: :sign)

      end
    end
  end
end