我正在运行一个简单的Sinatra应用程序,我希望它使用gzip压缩。我已经阅读了关于SO的各种问题,以及我在网上找到的文章,他们都建议将use Rack::Deflater
放在我的config.ru
文件中。这是该文件的样子:
require 'rubygems'
require 'bundler'
Bundler.require
if Sinatra::Base.development?
require 'dotenv'
Dotenv.load
end
require './app'
use Rack::Deflater
run myApp
设置完成后,我运行了bundle exec rackup
并使用curl进行了测试:
curl -i --head "Accept-Encoding: gzip,deflate" http://localhost:9292
出于某种原因,我没有从服务器获得gzip响应。这就是我所得到的:
# curl -i --head "Accept-Encoding: gzip,deflate" http://localhost:9292
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Mon, 16 Feb 2015 22:21:30 GMT
Content-Type: text/html
Connection: close
Location: http://localhost
Expires: Mon, 16 Feb 2015 22:21:29 GMT
Cache-Control: no-cache
HTTP/1.1 200 OK
Content-Type: text/html;charset=utf-8
Content-Length: 943
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Set-Cookie: rack.session=...; path=/; HttpOnly
Vary: Accept-Encoding
Connection: keep-alive
Server: thin
我截断了rack.session cookie,以便于阅读。有什么建议为什么会发生这种情况? 301重定向是否与它有关,如果是,为什么我首先获得301?谢谢!