rack-canonical-host 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rack-canonical-host.rb +9 -3
  2. metadata +3 -3
@@ -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 = (block_given? && block.call) || 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 @host && env['SERVER_NAME'] != @host
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#{@host}\\3/")
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
- - 2
9
- version: 0.0.2
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: 2010-11-18 00:00:00 -05:00
17
+ date: 2011-02-09 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency