diff options
Diffstat (limited to 'lib/chef_zero/rest_base.rb')
-rw-r--r-- | lib/chef_zero/rest_base.rb | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/chef_zero/rest_base.rb b/lib/chef_zero/rest_base.rb index bffcc35..1fa3f15 100644 --- a/lib/chef_zero/rest_base.rb +++ b/lib/chef_zero/rest_base.rb @@ -14,20 +14,19 @@ module ChefZero server.data end - def call(env) - rest_path = env['PATH_INFO'].split('/').select { |part| part != "" } - method = env['REQUEST_METHOD'].downcase.to_sym + def call(request) + method = request.method.downcase.to_sym if !self.respond_to?(method) accept_methods = [:get, :put, :post, :delete].select { |m| self.respond_to?(m) } accept_methods_str = accept_methods.map { |m| m.to_s.upcase }.join(', ') return [405, {"Content-Type" => "text/plain", "Allow" => accept_methods_str}, "Bad request method for '#{env['REQUEST_PATH']}': #{env['REQUEST_METHOD']}"] end - if json_only && !env['HTTP_ACCEPT'].split(';').include?('application/json') + if json_only && !request.env['HTTP_ACCEPT'].split(';').include?('application/json') return [406, {"Content-Type" => "text/plain"}, "Must accept application/json"] end # Dispatch to get()/post()/put()/delete() begin - self.send(method, RestRequest.new(env)) + self.send(method, request) rescue RestErrorResponse => e error(e.response_code, e.error) end |