Permalink
Browse files

Merge pull request #1 from DanielVartanov/master

Little improvements
  • Loading branch information...
2 parents 9826025 + 0979a20 commit b3f37f877b55113eab78a18570e8eb975041c9df @freegenie committed Jun 19, 2012
Showing with 13 additions and 13 deletions.
  1. +10 −11 lib/rack/canonical_host.rb
  2. +1 −0 rack-canonical-hostname.gemspec
  3. +2 −2 spec/canonical_host_spec.rb
View
@@ -1,6 +1,5 @@
module Rack
class CanonicalHost
-
VERSION = 0.1
def initialize(app, options = {})
@@ -10,18 +9,12 @@ def initialize(app, options = {})
@ignore = options.fetch(:ignore) { [] }
end
-
- def request_host
- @env['HTTP_HOST'].split(':').first
- end
-
def call(env)
- @env = env
- if request_host != @host && !@ignore.include?(request_host)
- uri = URI.parse ''
+ request = rack_request(env)
+
+ if request.host != @host && !@ignore.include?(request.host)
+ uri = URI.parse request.url
uri.host = @host
- uri.query = env['QUERY_STRING'] || ''
- uri.path = env['REQUEST_PATH'] || ''
uri.scheme = @scheme
status = 301
@@ -33,5 +26,11 @@ def call(env)
@app.call(env)
end
end
+
+ protected
+
+ def rack_request(env)
+ Rack::Request.new(env)
+ end
end
end
@@ -15,4 +15,5 @@ Gem::Specification.new do |gem|
gem.require_paths = ["lib"]
gem.version = Rack::CanonicalHost::VERSION
gem.add_development_dependency 'rspec', '~> 2.0'
+ gem.add_development_dependency 'rack'
end
@@ -33,7 +33,7 @@
response = Rack::MockRequest.new(app)
.get('/', {
'HTTP_HOST' => 'foo.example.org',
- 'REQUEST_PATH' => '/login'
+ 'PATH_INFO' => '/login'
})
response.headers['Location'].should =~ /\/login/
@@ -43,7 +43,7 @@
response = Rack::MockRequest.new(app)
.get('/', {
'HTTP_HOST' => 'foo.example.org',
- 'REQUEST_PATH' => '/login',
+ 'PATH_INFO' => '/login',
'QUERY_STRING' => 'a=10&b=20'
})

0 comments on commit b3f37f8

Please sign in to comment.