Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

After overriding the REQUEST_METHOD, store the original request method in "rack.methodoverride.original_method" #86

Open
wants to merge 1 commit into from

4 participants

@moonmaster9000

This is the same patch as #69 - I'm reopening it, because when you don't set rack.methodoverride.original_method after overriding the request method, there's no way to know what the original request was.

@joshfrench

+1, it would be useful to have a way of differentiating the original HTTP method.

@paulmand3l

+1 Not having this available is requiring some really nasty workarounds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 13, 2013
  1. @spastorino

    After overriding the REQUEST_METHOD, store the original request metho…

    spastorino authored Matt Parker committed
    …d in "rack.methodoverride.original_method"
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
View
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)
@env['rack.errors'].write(message)
end
end
+
+ # 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
end
end
View
13 test/context_test.rb
@@ -742,6 +742,19 @@
count.should.equal 3
end
+ 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 '/'
+ app.should.be.called
+ 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.