rack-canonical-host 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md
CHANGED
data/lib/rack/canonical_host.rb
CHANGED
@@ -18,8 +18,8 @@ module Rack
|
|
18
18
|
@ignore = options[:ignore]
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
|
21
|
+
def canonical?
|
22
|
+
known? || ignored?
|
23
23
|
end
|
24
24
|
|
25
25
|
def response
|
@@ -27,8 +27,13 @@ module Rack
|
|
27
27
|
[301, headers, [HTML_TEMPLATE % new_url]]
|
28
28
|
end
|
29
29
|
|
30
|
+
def known?
|
31
|
+
@host.nil? || request_uri.host == @host
|
32
|
+
end
|
33
|
+
private :known?
|
34
|
+
|
30
35
|
def ignored?
|
31
|
-
@ignore.include?(request_uri.host)
|
36
|
+
@ignore && @ignore.include?(request_uri.host)
|
32
37
|
end
|
33
38
|
private :ignored?
|
34
39
|
|
@@ -12,7 +12,7 @@ describe Rack::CanonicalHost do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
shared_context '
|
15
|
+
shared_context 'a matching request' do
|
16
16
|
context 'with a request to a matching host' do
|
17
17
|
let(:url) { 'http://example.com/full/path' }
|
18
18
|
|
@@ -23,7 +23,9 @@ describe Rack::CanonicalHost do
|
|
23
23
|
subject
|
24
24
|
end
|
25
25
|
end
|
26
|
+
end
|
26
27
|
|
28
|
+
shared_context 'a non-matching request' do
|
27
29
|
context 'with a request to a non-matching host' do
|
28
30
|
let(:url) { 'http://www.example.com/full/path' }
|
29
31
|
|
@@ -36,11 +38,22 @@ describe Rack::CanonicalHost do
|
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
41
|
+
shared_context 'matching and non-matching requests' do
|
42
|
+
include_context 'a matching request'
|
43
|
+
include_context 'a non-matching request'
|
44
|
+
end
|
45
|
+
|
39
46
|
context '#call' do
|
40
47
|
let(:env) { Rack::MockRequest.env_for(url) }
|
41
48
|
|
42
49
|
subject { app.call(env) }
|
43
50
|
|
51
|
+
context 'without a host' do
|
52
|
+
let(:app) { build_app(nil) }
|
53
|
+
|
54
|
+
include_context 'a matching request'
|
55
|
+
end
|
56
|
+
|
44
57
|
context 'without any options' do
|
45
58
|
let(:app) { build_app('example.com') }
|
46
59
|
|