2013-06-03 33 views
1

我在本地爲我的開發環境運行Webricks/Thin服務器,但是我無法在我的響應中返回Etag。如何在使用WEBRICK/Thin的rails 3.2.12中使用開發模式啓用Etag我使用WEBRICK/Thin的

我已經嘗試過所有關於添加Etag或ConditionalGet機架中間件組件的選項,但無濟於事。這裏是我的development.rb文件

config.middleware.use Rack::Cors do 
allow do 
    origins 'xyz:3000', 'abc:3000' 
    resource '*', :headers => :any, :methods => [:get, :post, :options] 
end 

config.middleware.insert_before(Rack::Cors, Rack::ConditionalGet) 
config.consider_all_requests_local  = true 
config.action_controller.perform_caching = true 

在這裏,段來自請求樣本響應報頭和那失蹤的eTag頁眉或HTTP_IF_NONE_MATCH和HTTP_IF_MODIFIED_SINCE頭,因此所有的請求返回200 OK,從來沒有在304未修改其中

> curl --head -I mylocalhosturl 
HTTP/1.1 200 OK 
Last-Modified: Mon, 04 Feb 2013 23:49:11 GMT 
Content-Type: application/json; charset=utf-8 
Cache-Control: must-revalidate, private, max-age=0 
X-Meta-Request-Version: 0.2.1 
X-Ua-Compatible: IE=Edge 
X-Request-Id: a06b5c3aeff8191ad22ab7d23433b076 
X-Runtime: 0.217688 
X-Rack-Cache: miss 
X-Miniprofiler-Ids: ["470heu3ps6wht3tuqgdr","qdjrpkjus6pzw6ed28ex","egfngxkdtl2f2m1w7r9n","b3dlozxj3hyb9bq2i2fi","k7x41fq7anewz5jf0nm1","unojexyqklkjdew8dkti","rjwo48jd8pw8c0h0jb38","82d8g9o6agzoam7acxgi","tk577xwtgtfn7u1mrvqo","e8ih8byjbm2jfmbyl5tf"] 
Content-Length: 0 
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-02-16) 
Date: Mon, 03 Jun 2013 18:34:31 GMT 
Connection: Keep-Alive 
Set-Cookie: __profilin=p%3Dt; path=/ 
Set-Cookie: __profilin=p%3Dt; path=/ 
Set-Cookie: __profilin=p%3Dt; path=/ 

有趣的是,這不是生產中使用類似配置AFAIK但nginx/1.2.0作爲服務器的問題。任何關於在Rail開發模式中啓用Etags的想法都會很讚賞。

回答

10

從項目中刪除rack-mini-profiler gem並重新啓動服務器。

由於某種原因rack-mini-profiler寶石將剝離Etags。我找到了這個SO帖子,因爲我正在找出爲什麼它會去掉Etags。

更新

您也可以根據Official Docs這樣

Rack::MiniProfiler.config.disable_caching = false 

請注意,禁用該行爲可能會出臺一些討厭的錯誤與rack-mini-profiler如文檔中提到禁用行爲

+0

太好了,幫了很多,謝謝。 – veritas1

+0

非常感謝。你剛纔救了我幾個小時。 – Tintin81

+0

或根據您的'production.rb'中的'Rack :: MiniProfiler.config.disable_caching = false'這樣的官方文檔禁用該行爲 https://github.com/MiniProfiler/rack-mini-profiler#caching-行爲 – MhdSyrwan

相關問題