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.
- checksums.yaml +4 -4
- data/lib/rack/host_redirect.rb +11 -4
- 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: 1e3c27cb40d8de5c16d81d5a43f5a15476883e4c
|
4
|
+
data.tar.gz: f8f7fdb448293426b705bdd496e37a28efd94950
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cc85d8214949f8cd9cf979badd1e00960ecbb83e3baa35cece5eb568379b00bf4670436fe32b471e11ca096c98c997efb3fa16a2bd8bfcf8cf5fe85c22a60c0
|
7
|
+
data.tar.gz: 27695222b5d3c9fb0cfac1c48c6d2f04f519c5164b279dd268164be07b8e28c452c7261ef6539389899d63d7b54a920fa0599a45e35b48f0d70a570aa1aa909f
|
data/lib/rack/host_redirect.rb
CHANGED
@@ -10,9 +10,8 @@ class Rack::HostRedirect
|
|
10
10
|
|
11
11
|
def call(env)
|
12
12
|
request = Rack::Request.new(env)
|
13
|
-
|
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.
|
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:
|
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
|
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
|