summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth Vargo <sethvargo@gmail.com>2013-05-16 16:47:34 -0400
committerSeth Vargo <sethvargo@gmail.com>2013-05-16 16:47:34 -0400
commitfa417efc4aec935b0d5c48db642a42d87b13fc9a (patch)
tree7c03f422b442d110b81a43155058189afe502620
parent5709c30083f89674b71ce8a7a5c9f81602cc97a3 (diff)
downloadchef-zero-fa417efc4aec935b0d5c48db642a42d87b13fc9a.tar.gz
Log debugging request and response
-rw-r--r--lib/chef_zero/rest_base.rb2
-rw-r--r--lib/chef_zero/rest_router.rb25
2 files changed, 18 insertions, 9 deletions
diff --git a/lib/chef_zero/rest_base.rb b/lib/chef_zero/rest_base.rb
index fe08069..f219ff1 100644
--- a/lib/chef_zero/rest_base.rb
+++ b/lib/chef_zero/rest_base.rb
@@ -14,8 +14,6 @@ module ChefZero
end
def call(request)
- ChefZero::Log.debug(request)
-
method = request.method.downcase.to_sym
if !self.respond_to?(method)
accept_methods = [:get, :put, :post, :delete].select { |m| self.respond_to?(m) }
diff --git a/lib/chef_zero/rest_router.rb b/lib/chef_zero/rest_router.rb
index 26b9522..d8919d3 100644
--- a/lib/chef_zero/rest_router.rb
+++ b/lib/chef_zero/rest_router.rb
@@ -12,18 +12,29 @@ module ChefZero
def call(request)
begin
- ChefZero::Log.debug "Request: #{request}"
+ ChefZero::Log.debug(request)
+
clean_path = "/" + request.rest_path.join("/")
- routes.each do |route, endpoint|
- if route.match(clean_path)
- return endpoint.call(request)
- end
- end
- not_found.call(request)
+
+ response = find_endpoint(clean_path).call(request)
+ ChefZero::Log.debug([
+ "",
+ "--- RESPONSE (#{response[0]}) ---",
+ response[2],
+ "--- END RESPONSE ---",
+ ].join("\n"))
+ return response
rescue
ChefZero::Log.error("#{$!.inspect}\n#{$!.backtrace.join("\n")}")
[500, {"Content-Type" => "text/plain"}, "Exception raised! #{$!.inspect}\n#{$!.backtrace.join("\n")}"]
end
end
+
+ private
+
+ def find_endpoint(clean_path)
+ _, endpoint = routes.find { |route, endpoint| route.match(clean_path) }
+ endpoint || not_found
+ end
end
end