rack-host-redirect 1.2.1 → 1.3.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rack/host_redirect.rb +11 -4
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 479c296ac20678a7529ac56a7dc6cb386f24c694
4
- data.tar.gz: 0e97489699cf6e05e24da9d6d729eb0f2439803f
3
+ metadata.gz: 1e3c27cb40d8de5c16d81d5a43f5a15476883e4c
4
+ data.tar.gz: f8f7fdb448293426b705bdd496e37a28efd94950
5
5
  SHA512:
6
- metadata.gz: 4693798c482dc943f0e593fa041b2cb40d65199c31e3c3d98c672d0e3826e07fa1d94b030cb06c7b89c9cf3ba711888700d49a7f5e9d59efbec44e5be4f77ddd
7
- data.tar.gz: 03221705bb00aec8bc9164cf892d1f5bbeb99176ba5e3f1c563ae7849319039c4f3d93d6c4f4c3edf8f0801c5e82e559e0f596be7194a35f5e226e0af9cd6881
6
+ metadata.gz: 9cc85d8214949f8cd9cf979badd1e00960ecbb83e3baa35cece5eb568379b00bf4670436fe32b471e11ca096c98c997efb3fa16a2bd8bfcf8cf5fe85c22a60c0
7
+ data.tar.gz: 27695222b5d3c9fb0cfac1c48c6d2f04f519c5164b279dd268164be07b8e28c452c7261ef6539389899d63d7b54a920fa0599a45e35b48f0d70a570aa1aa909f
@@ -10,9 +10,8 @@ class Rack::HostRedirect
10
10
 
11
11
  def call(env)
12
12
  request = Rack::Request.new(env)
13
- host = request.host.downcase # downcase for case-insensitive matching
14
-
15
- if updated_uri_opts = @host_mapping[host]
13
+
14
+ if updated_uri_opts = get_updated_uri_opts(request)
16
15
  location = update_url(request.url, updated_uri_opts)
17
16
  [301, {'Location' => location, 'Content-Type' => 'text/html', 'Content-Length' => '0'}, []]
18
17
  else
@@ -32,13 +31,15 @@ class Rack::HostRedirect
32
31
  raise ArgumentError, ":host key must be specified in #{opts.inspect}"
33
32
  end
34
33
 
34
+ exclude_proc = opts.delete(:exclude)
35
+
35
36
  [k].flatten.each do |oldhost|
36
37
  oldhost = oldhost.downcase
37
38
 
38
39
  if oldhost == opts[:host]
39
40
  raise ArgumentError, "#{oldhost.inspect} is being redirected to itself"
40
41
  else
41
- out[oldhost] = opts
42
+ out[oldhost] = [opts, exclude_proc]
42
43
  end
43
44
  end
44
45
 
@@ -46,6 +47,12 @@ class Rack::HostRedirect
46
47
  end
47
48
  end
48
49
 
50
+ def get_updated_uri_opts request
51
+ host = request.host.downcase # downcase for case-insensitive matching
52
+ uri_opts, exclude_proc = @host_mapping[host]
53
+ uri_opts unless exclude_proc && exclude_proc.call(request)
54
+ end
55
+
49
56
  def update_url url, opts
50
57
  uri = URI(url)
51
58
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-host-redirect
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoff Buesing
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-11 00:00:00.000000000 Z
11
+ date: 2017-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  version: '0'
67
67
  requirements: []
68
68
  rubyforge_project:
69
- rubygems_version: 2.2.0
69
+ rubygems_version: 2.5.2
70
70
  signing_key:
71
71
  specification_version: 4
72
72
  summary: Lean and simple host redirection via Rack middleware