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
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## Rack::CanonicalHost 0.0.6
4
+
5
+ * Prevent redirect if the canonical host name is `nil`
6
+
3
7
  ## Rack::CanonicalHost 0.0.5
4
8
 
5
9
  * Rename `ignored_hosts` option to `ignore`
@@ -14,7 +14,7 @@ module Rack
14
14
  host = host(env)
15
15
  redirect = Redirect.new(env, host, @options)
16
16
 
17
- if redirect.known_host?
17
+ if redirect.canonical?
18
18
  @app.call(env)
19
19
  else
20
20
  redirect.response
@@ -18,8 +18,8 @@ module Rack
18
18
  @ignore = options[:ignore]
19
19
  end
20
20
 
21
- def known_host?
22
- request_uri.host == @host || ignored?
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) if @ignore
36
+ @ignore && @ignore.include?(request_uri.host)
32
37
  end
33
38
  private :ignored?
34
39
 
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class CanonicalHost
3
- VERSION = '0.0.5'
3
+ VERSION = '0.0.6'
4
4
  end
5
5
  end
@@ -12,7 +12,7 @@ describe Rack::CanonicalHost do
12
12
  end
13
13
  end
14
14
 
15
- shared_context 'matching and non-matching requests' do
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-canonical-host
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: