Sha256: cb4ddc915d35a2ad7660324d3dfe22321c31127e82babd1276fe2db794a7e477

Contents?: true

Size: 1.79 KB

Versions: 51

Compression:

Stored size: 1.79 KB

Contents

require 'stringio'
require 'uri'

module Seahorse
  module Client
    module Http
      class Request

        # @option options [URI::HTTP, URI::HTTPS] :endpoint (nil)
        # @option options [String] :http_method ('GET')
        # @option options [Headers] :headers (Headers.new)
        # @option options [Body] :body (StringIO.new)
        def initialize(options = {})
          self.endpoint = options[:endpoint] if options[:endpoint]
          self.http_method = options[:http_method] || 'GET'
          self.headers = Headers.new(options[:headers] || {})
          self.body = options[:body]
        end

        # @return [URI::HTTP, URI::HTTPS, nil]
        attr_accessor :endpoint

        # @return [String] The HTTP request method, e.g. `GET`, `PUT`, etc.
        attr_accessor :http_method

        # @return [Headers] The hash of request headers.
        attr_accessor :headers

        # @return [IO]
        attr_reader :body

        # @param [String, URI::HTTP, URI::HTTPS, nil] endpoint
        def endpoint=(endpoint)
          endpoint = URI.parse(endpoint) if endpoint.is_a?(String)
          if endpoint.nil? or URI::HTTP === endpoint or URI::HTTPS === endpoint
            @endpoint = endpoint
          else
            msg = "invalid endpoint, expected URI::HTTP, URI::HTTPS, or nil, "
            msg << "got #{endpoint.inspect}"
            raise ArgumentError, msg
          end
        end

        # @return [String]
        def body_contents
          body.rewind
          contents = body.read
          body.rewind
          contents
        end

        # @param [#read, #size, #rewind] io
        def body=(io)
          @body =case io
            when nil then StringIO.new('')
            when String then StringIO.new(io)
            else io
          end
        end

      end
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
aws-sdk-core-2.0.48 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.47 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.46 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.45 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.44 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.43 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.42 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.41 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.40 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.39 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.38 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.37 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.36 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.35 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.34 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.33 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.32 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.31 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.30 lib/seahorse/client/http/request.rb
aws-sdk-core-2.0.29 lib/seahorse/client/http/request.rb