From 5b5d0e325d9b031638c0cebb128f2acc3dd764c4 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 1 Feb 2009 01:01:49 -0600 Subject: Use Rack::Head middleware to ensure the body is discarded for HEAD requests --- actionpack/lib/action_controller/integration.rb | 3 +++ actionpack/lib/action_controller/middlewares.rb | 1 + actionpack/test/controller/integration_test.rb | 14 ++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/actionpack/lib/action_controller/integration.rb b/actionpack/lib/action_controller/integration.rb index c335d638a1..a0e894108d 100644 --- a/actionpack/lib/action_controller/integration.rb +++ b/actionpack/lib/action_controller/integration.rb @@ -26,6 +26,9 @@ module ActionController # The status message that accompanied the status code of the last request. attr_reader :status_message + # The body of the last request. + attr_reader :body + # The URI of the last request. attr_reader :path diff --git a/actionpack/lib/action_controller/middlewares.rb b/actionpack/lib/action_controller/middlewares.rb index f9cfc2b18e..8ea1b5c7ce 100644 --- a/actionpack/lib/action_controller/middlewares.rb +++ b/actionpack/lib/action_controller/middlewares.rb @@ -19,3 +19,4 @@ end use "ActionController::RewindableInput" use "ActionController::ParamsParser" use "Rack::MethodOverride" +use "Rack::Head" diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 4f07cbee47..dc2c6fae49 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -266,6 +266,7 @@ class IntegrationProcessTest < ActionController::IntegrationTest assert_response :success assert_response :ok assert_equal({}, cookies) + assert_equal "OK", body assert_equal "OK", response.body assert_kind_of HTML::Document, html_document assert_equal 1, request_count @@ -281,6 +282,7 @@ class IntegrationProcessTest < ActionController::IntegrationTest assert_response :success assert_response :created assert_equal({}, cookies) + assert_equal "Created", body assert_equal "Created", response.body assert_kind_of HTML::Document, html_document assert_equal 1, request_count @@ -360,6 +362,18 @@ class IntegrationProcessTest < ActionController::IntegrationTest end end + def test_head + with_test_route_set do + head '/get' + assert_equal 200, status + assert_equal "", body + + head '/post' + assert_equal 201, status + assert_equal "", body + end + end + private def with_test_route_set with_routing do |set| -- cgit v1.2.3