Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Set env['rack.methodoverride.original_method'] to 'HEAD' when doing a HEAD request #69

wants to merge 1 commit into from

1 participant


This Pull Request fixes this issue rails/rails#7110 reported to Rails


I'm now considering that my take on the issue is wrong I will update ASAP


I'm closing this for now.
I wonder why are you converting HEAD requests to GET requests, that was part of the original issue.
I know that you could reuse the cache later but the app will never get HEAD requests as they are and will receive GET ones instead. I find that a bit weird.

/cc @rtomayko

@spastorino spastorino closed this
@joshfrench joshfrench referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 2 deletions.
  1. +10 −2 lib/rack/cache/context.rb
  2. +13 −0 test/context_test.rb
12 lib/rack/cache/context.rb
@@ -191,7 +191,7 @@ def lookup
# as a template for a conditional GET request with the backend.
def validate(entry)
# send no head requests because we want content
- @env['REQUEST_METHOD'] = 'GET'
+ convert_head_to_get!
# add our cached last-modified validator to the environment
@env['HTTP_IF_MODIFIED_SINCE'] = entry.last_modified
@@ -240,7 +240,7 @@ def validate(entry)
# caching of the response when the backend returns a 304.
def fetch
# send no head requests because we want content
- @env['REQUEST_METHOD'] = 'GET'
+ convert_head_to_get!
response = forward
@@ -295,5 +295,13 @@ def log(level, message)
+ # send no head requests because we want content
+ def convert_head_to_get!
+ if @env['REQUEST_METHOD'] == 'HEAD'
+ @env['REQUEST_METHOD'] = 'GET'
+ @env['rack.methodoverride.original_method'] = 'HEAD'
+ end
+ end
13 test/context_test.rb
@@ -742,6 +742,19 @@
count.should.equal 3
+ it 'stores HEAD as original_method on HEAD requests' do
+ respond_with do |req,res|
+ res.status = 200
+ res.body = []
+ req.request_method.should.equal 'GET'
+ req.env['rack.methodoverride.original_method'].should.equal 'HEAD'
+ end
+ head '/'
+ response.body.should.equal ''
+ end
it 'passes HEAD requests through directly on pass' do
respond_with do |req,res|
res.status = 200
Something went wrong with that request. Please try again.