HEAD request interpreted as GET in production #7110

Closed
edbond opened this Issue Jul 19, 2012 · 10 comments

Projects

None yet

5 participants

@edbond
Contributor
edbond commented Jul 19, 2012

TL;DR: curl -I (HEAD request) shows as HEAD in development mode, but GET in production.

> rails new headtest
      create  
      create  README.rdoc
      create  Rakefile
.........
Using rails (3.2.3) 
.........

> cd headtest
> rails g scaffold user email:string
> rake db:migrate
> rails s
=> Booting WEBrick
=> Rails 3.2.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-07-19 18:03:20] INFO  WEBrick 1.3.1
[2012-07-19 18:03:20] INFO  ruby 1.9.2 (2011-07-09) [x86_64-linux]
[2012-07-19 18:03:20] INFO  WEBrick::HTTPServer#start: pid=6426 port=3000

In other console
> curl -I http://localhost:3000/users
HTTP/1.1 200 OK 
Content-Type: text/html; charset=utf-8
X-Ua-Compatible: IE=Edge
Etag: "3569d81a77fe99a948814295f131ed3f"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: e2e41210912bc871f218ecc533432837
X-Runtime: 2.050671
Content-Length: 0
Server: WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
Date: Thu, 19 Jul 2012 15:05:51 GMT
Connection: Keep-Alive
Set-Cookie: _headtest_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWM3NWFjZjgxOWU2MjBmMzdlNTQ4YzliNjhlZjg1N2VjBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMXBFc0o1eEJPVzRkbVROa0FVdk5JTzNySSs0QXdlVzZZdzNWZk5IcWs5Rlk9BjsARg%3D%3D--d6114941cb9643c6991434d1460b60bdd7f8b3ee; path=/; HttpOnly

In webrick logs:
Started HEAD "/users" for 127.0.0.1 at 2012-07-19 18:05:49 +0300
Processing by UsersController#index as */*
  User Load (0.1ms)  SELECT "users".* FROM "users" 
  Rendered users/index.html.erb within layouts/application (14.7ms)
Compiled scaffolds.css  (70ms)  (pid 6426)
........
Completed 200 OK in 1069ms (Views: 918.8ms | ActiveRecord: 8.7ms)


Stop webrick 
> rake assets:precompile
> RAILS_ENV=production rake db:migrate
==  CreateUsers: migrating ====================================================
-- create_table(:users)
   -> 0.0015s
==  CreateUsers: migrated (0.0017s) ===========================================

> rails s -e production
=> Booting WEBrick
=> Rails 3.2.3 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-07-19 18:12:00] INFO  WEBrick 1.3.1
[2012-07-19 18:12:00] INFO  ruby 1.9.2 (2011-07-09) [x86_64-linux]
[2012-07-19 18:12:00] INFO  WEBrick::HTTPServer#start: pid=6612 port=3000

> curl -I http://localhost:3000/users
HTTP/1.1 200 OK 
Content-Type: text/html; charset=utf-8
X-Ua-Compatible: IE=Edge,chrome=1
Etag: "e83291d36518c38537fd37ed533830b6"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 084d3ec6698e68864f0589a36a6a324b
X-Runtime: 0.274968
Date: Thu, 19 Jul 2012 15:13:08 GMT
X-Rack-Cache: miss
Content-Length: 0
Server: WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
Connection: Keep-Alive
Set-Cookie: _headtest_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWM3NDVlZGJjOTQwODY4NDcyZDYzNWU5Nzk1MDAwNWYxBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMXI2TlNpa29rcTNIdFIzcCt6cXBuQlJpVE9BMldUelpVZENmU1VMczVEVEE9BjsARg%3D%3D--a2c403b215de134d171bc40a9b2f58e19731f6b4; path=/; HttpOnly


AND:
Started GET "/users" for 127.0.0.1 at 2012-07-19 18:13:08 +0300
Processing by UsersController#index as */*
  Rendered users/index.html.erb within layouts/application (14.3ms)
Completed 200 OK in 195ms (Views: 87.7ms | ActiveRecord: 9.5ms)

I expect HEAD not GET request.
request.head? fails.

Latest version affected too.
Rails 3.2.6

@acapilleri
Contributor

do you have the same configuration in development.rband `production.rb``?

@edbond
Contributor
edbond commented Jul 19, 2012

I generated project with 'rails new' command. Both configurations is default.

@acapilleri
Contributor

if set config.action_controller.perform_caching = false in production.rb the request is a HEAD

but maybe it has no sense on production env

@edbond
Contributor
edbond commented Jul 19, 2012

Thanks, this helps.
I don't understand how perform_caching correlate with changing request method.

@spastorino
Member

This is a rack-cache issue rtomayko/rack-cache#69

@spastorino spastorino closed this Jul 21, 2012
@spastorino
Member

If someone can test that using my rack-cache branch, please let me know if works fine

@carlosantoniodasilva

@spastorino if that does get merged, what happens to the dispatch::head middleware?

@josevalim
Member

Maybe just move the dispatch::head middleware above rack-cache?

@spastorino
Member

Yep I was talking with @josevalim probably the best is to move Head middleware above rack-cache and backport Head middleware to Rack. If the backport to Rack doesn't get accepted I think my PR should be merged because Rack's Head https://github.com/rack/rack/blob/master/lib/rack/head.rb is not Rails' Head https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/head.rb. The one in Rack doesn't change the method.

@spastorino spastorino added a commit to spastorino/rails that referenced this issue Jul 23, 2012
@spastorino spastorino Remove ActionDispatch::Head middleware in favor of Rack::Head
Closes #7110 there's more work to do on rack-cache issue 69
cf93e58
@spastorino spastorino added a commit that referenced this issue Jul 23, 2012
@spastorino spastorino Remove ActionDispatch::Head middleware in favor of Rack::Head
Closes #7110 there's more work to do on rack-cache issue 69
449039a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment