class RestClient::Request
Reopen the RestClient::Request
class to add a level of indirection in order to create the stack of Rack
middleware.
Public Instance Methods
execute(&block)
click to toggle source
# File lib/restclient/components.rb, line 100 def execute(&block) uri = URI.parse(@url) # minimal rack spec env = { "restclient.hash" => { :request => self, :error => nil, :block => block }, "REQUEST_METHOD" => @method.to_s.upcase, "SCRIPT_NAME" => "", "PATH_INFO" => uri.path || "/", "QUERY_STRING" => uri.query || "", "SERVER_NAME" => uri.host, "SERVER_PORT" => uri.port.to_s, "rack.version" => ::Rack::VERSION, "rack.run_once" => false, "rack.multithread" => true, "rack.multiprocess" => true, "rack.url_scheme" => uri.scheme, "rack.input" => payload || StringIO.new().set_encoding("ASCII-8BIT"), "rack.errors" => $stderr } @processed_headers.each do |key, value| env.merge!("HTTP_"+key.to_s.gsub("-", "_").upcase => value) end if content_type = env.delete('HTTP_CONTENT_TYPE') env['CONTENT_TYPE'] = content_type end if content_length = env.delete('HTTP_CONTENT_LENGTH') env['CONTENT_LENGTH'] = content_length end stack = RestClient::RACK_APP RestClient.components.each do |(component, args)| if (args || []).empty? stack = component.new(stack) else stack = component.new(stack, *args) end end response = stack.call(env) # allow to use the response block, even if not using the Compatibility component unless RestClient.enabled?(RestClient::Rack::Compatibility) if block = env['restclient.hash'][:block] block.call(response) end end response end
Also aliased as: original_execute