public
Rubygem
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Click here to lend your support to: thin and make a donation at www.pledgie.com !
Serve static file only on GET and HEAD requests in Rails adapter, fixes #58
macournoyer (author)
Wed Apr 02 17:49:23 -0700 2008
commit  1d1faea0401103e2d16cfb38b19d7fd133053cb5
tree    fbcf407c7fe50067672e6b993de7a5d2af1a398b
parent  8968de296a0edc8a233ae8d7d2717615f0305815
...
1
 
2
3
4
...
1
2
3
4
5
0
@@ -1,4 +1,5 @@
0
 == 0.8.0 ??? release
0
+ * Serve static file only on GET and HEAD requests in Rails adapter, fixes #58
0
  * Add threaded option to run server in threaded mode, calling the application in a
0
    thread allowing for concurrency in the Rack adapter, closes #46
0
  * Guess which adapter to use from directory (chdir option)
...
13
14
15
 
 
16
17
18
...
56
57
58
 
59
60
61
62
63
64
65
66
67
 
 
 
 
 
 
 
68
 
 
 
69
70
71
...
13
14
15
16
17
18
19
20
...
58
59
60
61
62
63
 
 
 
 
 
 
 
64
65
66
67
68
69
70
71
72
73
74
75
76
77
0
@@ -13,6 +13,8 @@ require 'cgi'
0
 module Rack
0
   module Adapter 
0
     class Rails
0
+      FILE_METHODS = %w(GET HEAD).freeze
0
+      
0
       def initialize(options={})
0
         @root   = options[:root]         || Dir.pwd
0
         @env    = options[:environment]  || 'development'
0
@@ -56,16 +58,20 @@ module Rack
0
       
0
       def call(env)
0
         path        = env['PATH_INFO'].chomp('/')
0
+        method      = env['REQUEST_METHOD']
0
         cached_path = (path.empty? ? 'index' : path) + ActionController::Base.page_cache_extension
0
         
0
-        if file_exist?(path)              # Serve the file if it's there
0
-          serve_file(env)
0
-        elsif file_exist?(cached_path)    # Serve the page cache if it's there
0
-          env['PATH_INFO'] = cached_path
0
-          serve_file(env)
0
-        else                              # No static file, let Rails handle it
0
-          serve_rails(env)
0
+        if FILE_METHODS.include?(method)
0
+          if file_exist?(path)              # Serve the file if it's there
0
+            return serve_file(env)
0
+          elsif file_exist?(cached_path)    # Serve the page cache if it's there
0
+            env['PATH_INFO'] = cached_path
0
+            return serve_file(env)
0
+          end
0
         end
0
+        
0
+        # No static file, let Rails handle it
0
+        serve_rails(env)
0
       end
0
     
0
       protected
...
56
57
58
 
 
 
 
 
 
 
 
 
 
 
 
59
60
61
...
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
0
@@ -56,6 +56,18 @@ begin
0
       res.body.should == 'cached'
0
     end
0
     
0
+    it "should not serve page cache on POST request" do
0
+      res = @request.get("/simple/cached?value=cached")
0
+
0
+      res.should be_ok
0
+      res.body.should == 'cached'
0
+      
0
+      res = @request.post("/simple/cached?value=notcached")
0
+      
0
+      res.should be_ok
0
+      res.body.should == 'notcached'
0
+    end
0
+    
0
     it "handles multiple cookies" do
0
       res = @request.get('/simple/set_cookie?name=a&value=1')
0
     

Comments