class RestClient::Rack::Compatibility
Public Class Methods
new(app)
click to toggle source
# File lib/restclient/components.rb, line 7 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/restclient/components.rb, line 11 def call(env) status, header, body = @app.call(env) net_http_response = RestClient::MockNetHTTPResponse.new(body, status, header) content = "" net_http_response.body.each{|line| content << line} request = env['restclient.hash'][:request] response = case RestClient::Response.method(:create).arity when 4 then RestClient::Response.create(content, net_http_response, request, self) else RestClient::Response.create(content, net_http_response, request) end if block = env['restclient.hash'][:block] block.call(response) # only raise error if response is not successful elsif !(200...300).include?(response.code) && e = env['restclient.hash'][:error] raise e else response end end