From d40a8494c828585ff9b71156e07d76774cc845a7 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Tue, 26 Jun 2012 15:30:55 -0700 Subject: [PATCH] Do not return response body for HEAD requests "The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response." http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4 Signed-off-by: Stephen Celis --- lib/grape/endpoint.rb | 1 + spec/grape/api_spec.rb | 2 +- spec/grape/endpoint_spec.rb | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/grape/endpoint.rb b/lib/grape/endpoint.rb index 3ec4ad3eb0..d11f7efea1 100644 --- a/lib/grape/endpoint.rb +++ b/lib/grape/endpoint.rb @@ -296,6 +296,7 @@ def run(env) def build_middleware b = Rack::Builder.new + b.use Rack::Head b.use Grape::Middleware::Error, :default_status => settings[:default_error_status] || 403, :rescue_all => settings[:rescue_all], diff --git a/spec/grape/api_spec.rb b/spec/grape/api_spec.rb index 78e9bc0f02..88aacb2461 100644 --- a/spec/grape/api_spec.rb +++ b/spec/grape/api_spec.rb @@ -284,7 +284,7 @@ def app; subject end verb end send(verb, '/example') - last_response.body.should eql verb + last_response.body.should eql verb == 'head' ? '' : verb # Call it with a method other than the properly constrained one. send(verbs[(verbs.index(verb) + 1) % verbs.size], '/example') last_response.status.should eql 404 diff --git a/spec/grape/endpoint_spec.rb b/spec/grape/endpoint_spec.rb index 36c3843bf8..704f8c925d 100644 --- a/spec/grape/endpoint_spec.rb +++ b/spec/grape/endpoint_spec.rb @@ -410,7 +410,7 @@ def memoized end send(verb, '/example/and/some/more') last_response.status.should eql (verb == "post" ? 201 : 200) - last_response.body.should eql verb + last_response.body.should eql verb == 'head' ? '' : verb end end end