slimmer 3.9.2 → 3.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,17 +32,20 @@ module Slimmer
32
32
  def call(env)
33
33
  logger.debug "Slimmer: capturing response"
34
34
  status, headers, body = @app.call(env)
35
- response = Rack::Response.new(body, status, headers)
36
35
 
37
- if response_can_be_rewritten?(response) && !skip_slimmer?(env, response)
38
- status, headers, body = rewrite_response(env, response)
36
+ if response_can_be_rewritten?(status, headers)
37
+ response = Rack::Response.new(body, status, headers)
38
+
39
+ if !skip_slimmer?(env, response)
40
+ status, headers, body = rewrite_response(env, response)
41
+ end
39
42
  end
40
43
 
41
44
  [status, strip_slimmer_headers(headers), body]
42
45
  end
43
46
 
44
- def response_can_be_rewritten?(response)
45
- response.content_type =~ /text\/html/ && ![301, 302, 304].include?(response.status)
47
+ def response_can_be_rewritten?(status, headers)
48
+ Rack::Utils::HeaderHash.new(headers)["Content-Type"] =~ /text\/html/ && ![301, 302, 304].include?(status)
46
49
  end
47
50
 
48
51
  def skip_slimmer?(env, response)
@@ -1,3 +1,3 @@
1
1
  module Slimmer
2
- VERSION = '3.9.2'
2
+ VERSION = '3.9.3'
3
3
  end
@@ -47,6 +47,25 @@ module TypicalUsage
47
47
  end
48
48
  end
49
49
 
50
+ class SkipDoesntInteractWithNonHtmlBodies < SlimmerIntegrationTest
51
+ def test_non_html_response_bodies_are_passed_through_untouched
52
+ # Rack::SendFile doesn't work if to_s, to_str or each are called on the
53
+ # response body (as happens when building a Rack::Response)
54
+ body = stub('body')
55
+ inner_app = proc { |env|
56
+ [200, {"Content-Type" => "application/json"}, body]
57
+ }
58
+ app = Slimmer::App.new inner_app, {asset_host: "http://template.local"}
59
+
60
+ body.expects(:to_s).never
61
+ body.expects(:to_str).never
62
+ body.expects(:each).never
63
+ Rack::Response.expects(:new).never
64
+
65
+ app.call({})
66
+ end
67
+ end
68
+
50
69
  class ContentLengthTest < SlimmerIntegrationTest
51
70
  given_response 200, %{
52
71
  <html>
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: slimmer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 3.9.2
5
+ version: 3.9.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ben Griffiths
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2012-11-12 00:00:00 Z
14
+ date: 2012-11-14 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: nokogiri
@@ -246,7 +246,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
246
246
  requirements:
247
247
  - - ">="
248
248
  - !ruby/object:Gem::Version
249
- hash: -1627984955409048265
249
+ hash: 4458894568603330614
250
250
  segments:
251
251
  - 0
252
252
  version: "0"
@@ -255,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
255
  requirements:
256
256
  - - ">="
257
257
  - !ruby/object:Gem::Version
258
- hash: -1627984955409048265
258
+ hash: 4458894568603330614
259
259
  segments:
260
260
  - 0
261
261
  version: "0"