cloudfront_asset_host 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cloudfront_asset_host}
8
- s.version = "1.0.1"
8
+ s.version = "1.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Menno van der Sman"]
12
- s.date = %q{2010-03-18}
12
+ s.date = %q{2010-03-23}
13
13
  s.description = %q{Easy deployment of your assets on CloudFront or S3 using a simple rake-task. When enabled in production, the application's asset_host and public_paths will point to the correct location.}
14
14
  s.email = %q{menno@wakoopa.com}
15
15
  s.extra_rdoc_files = [
@@ -55,7 +55,12 @@ module CloudfrontAssetHost
55
55
 
56
56
  if source && request && CloudfrontAssetHost.gzip
57
57
  gzip_allowed = CloudfrontAssetHost.gzip_allowed_for_source?(source)
58
- gzip_accepted = !(request.headers['User-Agent'].to_s =~ /(Mozilla\/4\.0[678])|(MSIE\s[1-6])/) && request.headers['Accept-Encoding'].to_s.include?('gzip')
58
+
59
+ # Only Netscape 4 does not support gzip
60
+ # IE masquerades as Netscape 4, so we check that as well
61
+ user_agent = request.headers['User-Agent'].to_s
62
+ gzip_accepted = !(user_agent =~ /^Mozilla\/4/) || user_agent =~ /\bMSIE/
63
+ gzip_accepted &&= request.headers['Accept-Encoding'].to_s.include?('gzip')
59
64
 
60
65
  if gzip_accepted && gzip_allowed
61
66
  host << "/#{CloudfrontAssetHost.gzip_prefix}"
@@ -34,23 +34,46 @@ class CloudfrontAssetHostTest < Test::Unit::TestCase
34
34
  context "asset-host" do
35
35
 
36
36
  setup do
37
- @gzip_request = stub(:headers => {'Accept-Encoding' => 'gzip, compress'})
38
- @request = stub(:headers => {})
39
- @img_source = "/images/logo.png"
40
- @js_source = "/javascripts/application.js"
37
+ @source = "/javascripts/application.js"
41
38
  end
42
39
 
43
40
  should "use cname for asset_host" do
44
- assert_equal "http://assethost.com", CloudfrontAssetHost.asset_host(@img_source, @request)
41
+ assert_equal "http://assethost.com", CloudfrontAssetHost.asset_host(@source)
45
42
  end
46
43
 
47
44
  should "use bucket_host when cname is not present" do
48
45
  CloudfrontAssetHost.cname = nil
49
- assert_equal "http://bucketname.s3.amazonaws.com", CloudfrontAssetHost.asset_host(@img_source, @request)
46
+ assert_equal "http://bucketname.s3.amazonaws.com", CloudfrontAssetHost.asset_host(@source)
50
47
  end
51
48
 
52
- should "add gz to asset_host when applicable" do
53
- assert_equal "http://assethost.com/gz", CloudfrontAssetHost.asset_host(@js_source, @gzip_request)
49
+ should "not support gzip for images" do
50
+ request = stub(:headers => {'User-Agent' => 'Mozilla/5.0', 'Accept-Encoding' => 'gzip, compress'})
51
+ source = "/images/logo.png"
52
+ assert_equal "http://assethost.com", CloudfrontAssetHost.asset_host(source, request)
53
+ end
54
+
55
+ context "when taking the headers into account" do
56
+
57
+ should "support gzip for IE" do
58
+ request = stub(:headers => {'User-Agent' => 'Mozilla/4.0 (compatible; MSIE 8.0)', 'Accept-Encoding' => 'gzip, compress'})
59
+ assert_equal "http://assethost.com/gz", CloudfrontAssetHost.asset_host(@source, request)
60
+ end
61
+
62
+ should "support gzip for modern browsers" do
63
+ request = stub(:headers => {'User-Agent' => 'Mozilla/5.0', 'Accept-Encoding' => 'gzip, compress'})
64
+ assert_equal "http://assethost.com/gz", CloudfrontAssetHost.asset_host(@source, request)
65
+ end
66
+
67
+ should "support not support gzip for Netscape 4" do
68
+ request = stub(:headers => {'User-Agent' => 'Mozilla/4.0', 'Accept-Encoding' => 'gzip, compress'})
69
+ assert_equal "http://assethost.com", CloudfrontAssetHost.asset_host(@source, request)
70
+ end
71
+
72
+ should "require gzip in accept-encoding" do
73
+ request = stub(:headers => {'User-Agent' => 'Mozilla/5.0'})
74
+ assert_equal "http://assethost.com", CloudfrontAssetHost.asset_host(@source, request)
75
+ end
76
+
54
77
  end
55
78
 
56
79
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 1
9
- version: 1.0.1
8
+ - 2
9
+ version: 1.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Menno van der Sman
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-18 00:00:00 +01:00
17
+ date: 2010-03-23 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency