rack-canonical-host 0.0.2 → 0.0.3
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/lib/rack-canonical-host.rb +9 -3
- metadata +3 -3
data/lib/rack-canonical-host.rb
CHANGED
@@ -2,7 +2,8 @@ module Rack # :nodoc:
|
|
2
2
|
class CanonicalHost
|
3
3
|
def initialize(app, host=nil, &block)
|
4
4
|
@app = app
|
5
|
-
@host =
|
5
|
+
@host = host
|
6
|
+
@block = block
|
6
7
|
end
|
7
8
|
|
8
9
|
def call(env)
|
@@ -14,11 +15,16 @@ module Rack # :nodoc:
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def url(env)
|
17
|
-
if
|
18
|
+
if (host = host(env)) && env['SERVER_NAME'] != host
|
18
19
|
url = Rack::Request.new(env).url
|
19
|
-
url.sub(%r{\A(https?://)(.*?)(:\d+)?(/|$)}, "\\1#{
|
20
|
+
url.sub(%r{\A(https?://)(.*?)(:\d+)?(/|$)}, "\\1#{host}\\3/")
|
20
21
|
end
|
21
22
|
end
|
22
23
|
private :url
|
24
|
+
|
25
|
+
def host(env)
|
26
|
+
@block ? @block.call(env) || @host : @host
|
27
|
+
end
|
28
|
+
private :host
|
23
29
|
end
|
24
30
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Tyler Hunt
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-02-09 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|