I think the problem might be ActionDispatch :: Head middleware. Part of this code:
def call(env) if env["REQUEST_METHOD"] == "HEAD" env["REQUEST_METHOD"] = "GET" env["rack.methodoverride.original_method"] = "HEAD" status, headers, _ = @app.call(env) [status, headers, []] else @app.call(env) end end
Thus, essentially the middleware modifies the request method before the router even receives the request. If you want your router to handle the difference between HEAD and GET requests, you can remove the middleware by adding
config.middleware.delete "ActionDispatch::Head"
to your application.rb
Otherwise, you must have access to this variable in your controller as follows:
if request.env["rack.methodoverride.original_method"]=='HEAD' #do head processing here head :ok, :additional_header => 'value' else #do get processing here end
If you are worried about performance, I suggest writing your own middleware to handle these requests. Railscasts has some good guides on this .
Also note that other intermediaries, such as Rack :: Cache, may also interfere with this process. Therefore, you should insert your middleware on top:
config.middleware.insert_before 0, "YourMiddleware"
source share