browser 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/browser/middleware.rb +13 -3
- data/lib/browser/version.rb +1 -1
- data/test/middleware_test.rb +7 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b3b6a159e6f696022dbcf224f2366040a014066
|
4
|
+
data.tar.gz: 12cfb603efd44bfa40a6211dc81cdbfc8cc3175a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73d07937171c917f60c801a15f6d7ad4fe637d041c49b7fee0eb0327d8cbeaeeda0e1322ee08e208021e689ff7a357e4af6aa1e9d532f7e4705fda8289511de2
|
7
|
+
data.tar.gz: bcee3558d4278b99921b93d6eb8763d640c475da9e5351b6c3f8f692ba6f7984427d2020c5eb0ad146b34d70286ef020731c7fd73732650672da3b3136e178fe
|
data/lib/browser/middleware.rb
CHANGED
@@ -5,6 +5,9 @@ class Browser
|
|
5
5
|
# Detect the most common assets.
|
6
6
|
ASSETS_REGEX = %r[\.(css|png|jpe?g|gif|js|svg|ico|flv|mov|m4v|ogg|swf)\z]i
|
7
7
|
|
8
|
+
# Detect the ACCEPT header. IE8 send */*.
|
9
|
+
ACCEPT_REGEX = %r[(text/html|\*/\*)]
|
10
|
+
|
8
11
|
def initialize(app, &block)
|
9
12
|
raise ArgumentError, "Browser::Middleware requires a block" unless block
|
10
13
|
|
@@ -18,7 +21,7 @@ class Browser
|
|
18
21
|
# Only apply verification on HTML requests.
|
19
22
|
# This ensures that images, CSS and JavaScript
|
20
23
|
# will be rendered.
|
21
|
-
return run_app(env) unless
|
24
|
+
return run_app(env) unless process?(request)
|
22
25
|
|
23
26
|
path = catch(:redirected) do
|
24
27
|
Context.new(request).instance_eval(&@block)
|
@@ -48,9 +51,16 @@ class Browser
|
|
48
51
|
@app.call(env)
|
49
52
|
end
|
50
53
|
|
54
|
+
def process?(request)
|
55
|
+
html?(request) && !assets?(request)
|
56
|
+
end
|
57
|
+
|
51
58
|
def html?(request)
|
52
|
-
|
53
|
-
|
59
|
+
request.env["HTTP_ACCEPT"].to_s.match(ACCEPT_REGEX)
|
60
|
+
end
|
61
|
+
|
62
|
+
def assets?(request)
|
63
|
+
request.path.match(ASSETS_REGEX)
|
54
64
|
end
|
55
65
|
end
|
56
66
|
end
|
data/lib/browser/version.rb
CHANGED
data/test/middleware_test.rb
CHANGED
@@ -35,6 +35,13 @@ class MiddlewareTest < Test::Unit::TestCase
|
|
35
35
|
assert_equal 404, last_response.status
|
36
36
|
end
|
37
37
|
|
38
|
+
def test_redirect_ie8_with_wildcard_http_accept
|
39
|
+
get "/", {}, {"HTTP_USER_AGENT" => "MSIE 8", "HTTP_ACCEPT" => "*/*"}
|
40
|
+
follow_redirect!
|
41
|
+
|
42
|
+
assert_equal 404, last_response.status
|
43
|
+
end
|
44
|
+
|
38
45
|
def test_ignores_non_html_requests
|
39
46
|
get "/", {}, {"HTTP_USER_AGENT" => "MSIE 6", "HTTP_ACCEPT" => "image/png"}
|
40
47
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: browser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
159
|
version: '0'
|
160
160
|
requirements: []
|
161
161
|
rubyforge_project:
|
162
|
-
rubygems_version: 2.2.
|
162
|
+
rubygems_version: 2.2.2
|
163
163
|
signing_key:
|
164
164
|
specification_version: 4
|
165
165
|
summary: Do some browser detection with Ruby.
|