class Excon::Connection
def request(params, &block)
(**params)
-
:scheme
(String
) -- The protocol; 'https' causes OpenSSL to be used -
:query
(Hash
) -- appended to the 'scheme://host:port/path/' in the form of '?key=value' -
:port
(Fixnum
) -- The port on which to connect, to the destination host -
:path
(String
) -- appears after 'scheme://host:port/' -
:host
(String
) -- The destination host's reachable DNS name or IP, in the form of a String -
:headers
(Hash
) -- The default headers to supply in a request -
:body
(String
) -- text to be sent over a socket
Parameters:
-
params
(Hash
) -- One or more optional params, override defaults set in Connection.new
Other tags:
- Yield: - @see Response#self.parse
def request(params, &block) # @data has defaults, merge in new params to override datum = @data.merge(params) invalid_keys_warning(params, VALID_CONNECTION_KEYS) datum[:headers] = @data[:headers].merge(datum[:headers] || {}) datum[:headers]['Host'] ||= '' << datum[:host] << ':' << datum[:port].to_s datum[:retries_remaining] ||= datum[:retry_limit] # if path is empty or doesn't start with '/', insert one unless datum[:path][0, 1] == '/' datum[:path].insert(0, '/') end if block_given? $stderr.puts("Excon requests with a block are deprecated, pass :response_block instead (#{caller.first})") datum[:response_block] = Proc.new end datum[:connection] = self datum[:stack] = datum[:middlewares].map do |middleware| lambda {|stack| middleware.new(stack)} end.reverse.inject(self) do |middlewares, middleware| middleware.call(middlewares) end datum = datum[:stack].request_call(datum) unless datum[:pipeline] datum = response(datum) if datum[:response][:headers]['Connection'] == 'close' reset end Excon::Response.new(datum[:response]) else datum end rescue => error datum[:error] = error if datum[:stack] datum[:stack].error_call(datum) else raise error end end