- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近在此 Thoughtbot blog post 之后在我的 Rails 4 应用程序上启用了 GZIP我还添加了 use Rack::Deflater
按照 this post 的建议添加到我的 config.ru 文件中.我的 Rails 应用程序似乎提供压缩内容,但是当我使用 RSpec 对其进行测试时,测试失败,因为 response.headers['Content-Encoding']
为零。
这是我的 application.rb:
module MyApp
class Application < Rails::Application
# Turn on GZIP compression
config.middleware.use Rack::Deflater
end
end
require 'rails_helper'
describe GeneralController, type: :controller, focus: true do
it "a visitor has a browser that supports compression" do
['deflate', 'gzip', 'deflate,gzip', 'gzip,deflate'].each do |compression_method|
get 'about', {}, {'HTTP_ACCEPT_ENCODING' => compression_method }
binding.pry
expect(response.headers['Content-Encoding']).to be
end
end
it "a visitor's browser does not support compression" do
get 'about'
expect(response.headers['Content-Encoding']).to_not be
end
end
curl --head -H "Accept-Encoding: gzip" http://localhost:3000/
我得到以下输出:
HTTP/1.1 200 OK
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Ua-Compatible: chrome=1
Content-Type: text/html; charset=utf-8
Vary: Accept-Encoding
Content-Encoding: gzip
Etag: "f7e364f21dbb81b9580cd39e308a7c15"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 3f018f27-40ab-4a87-a836-67fdd6bd5b6e
X-Runtime: 0.067748
Server: WEBrick/1.3.1 (Ruby/2.0.0/2014-02-24)
Rack::Deflater
的实现是否存在问题.
最佳答案
正如@andy-waite 所指出的,RSpec Controller 规范不知道中间件,但这就是为什么,自从 RSpec 2.6 我们有 request specs .
根据文档,请求规范是:
designed to drive behavior through the full stack
require 'rails_helper'
describe GeneralController, type: :request, focus: true do
it "a visitor has a browser that supports compression" do
['deflate', 'gzip', 'deflate,gzip', 'gzip,deflate'].each do |compression_method|
get 'about', {}, {'HTTP_ACCEPT_ENCODING' => compression_method }
binding.pry
expect(response.headers['Content-Encoding']).to be
end
end
it "a visitor's browser does not support compression" do
get 'about'
expect(response.headers['Content-Encoding']).to_not be
end
end
关于ruby-on-rails - GZIPed 响应的 Rspec 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30516523/
我最近在此 Thoughtbot blog post 之后在我的 Rails 4 应用程序上启用了 GZIP我还添加了 use Rack::Deflater按照 this post 的建议添加到我的
我想知道 nginx 是否可以将 gzip 压缩的内容保存在缓存中,或者它一直 gzip 文件? 通过“保留缓存”,我的意思是内存或磁盘中的某些东西,在服务器端(没有浏览器缓存)。 因为我看到静态压缩
我试图让一段打开 http 连接的代码工作。然而,网页可以以纯文本或 gzip 格式传输。因此,具有实用主义的代码会尝试以纯文本形式打开,如果失败并接收到异常,则尝试使用 gzip 编码。 URL 是
我需要向 Web 服务器发送 POST 请求,并能够读取该服务器发送的响应。 我尝试使用带有以下代码的 HTTPBuilder 库: def http = new HTTPBuilder('http:
我的代码如下所示,但我无法成功获得响应。我的代码有什么问题吗? 代码: $headers = array('Content-Type: text/xml;charset=UTF-8','Content
我正在尝试做一个接受压缩响应的请求 var request = (HttpWebRequest)HttpWebRequest.Create(requestUri); request.Headers.A
这是我尝试过的随机顺序的列表: AddHandler application/x-httpd-php .otf AddType default_mimetype auto_prepend_file =
我启用了 Amazon CloudFront gzip 功能:“Compress Objects Automatically”。 我的 CloudFront 中的所有文件都会发生这种情况,而其他 CS
为什么 IE 10 和 11 无法加载 GZiped 内容(js 和 css)?当我从支持 gzip 压缩的服务器加载页面时,IE 加载第一个 HTML 页面但无法加载其他 js 和 css 文件。在
我是一名优秀的程序员,十分优秀!