rack-canonical-hostname 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,7 +12,7 @@ Redirect preserves path and querystring.
12
12
 
13
13
  Add this line to your application's Gemfile:
14
14
 
15
- gem 'rack-canonical-host', :require => 'rack/canonical_host'
15
+ gem 'rack-canonical-hostname', :require => 'rack/canonical_host'
16
16
 
17
17
  And then execute:
18
18
 
@@ -20,7 +20,7 @@ And then execute:
20
20
 
21
21
  Or install it yourself as:
22
22
 
23
- $ gem install rack-canonical-host
23
+ $ gem install rack-canonical-hostname
24
24
 
25
25
  ## Usage
26
26
 
@@ -36,7 +36,7 @@ Example for rails configuration:
36
36
  config.middleware.insert_before Rack::Lock, Rack::CanonicalHost, {
37
37
  :host => 'my-site.com',
38
38
  :scheme => 'https',
39
- :ignore => ['staging.my-site.com', 'balabik-staging.herokuapp.com']
39
+ :ignore => ['staging.my-site.com', 'my-site-staging.herokuapp.com']
40
40
  }
41
41
  ```
42
42
 
@@ -1,7 +1,6 @@
1
1
  module Rack
2
2
  class CanonicalHost
3
-
4
- VERSION = 0.1
3
+ VERSION = 0.2
5
4
 
6
5
  def initialize(app, options = {})
7
6
  @app = app
@@ -10,18 +9,12 @@ module Rack
10
9
  @ignore = options.fetch(:ignore) { [] }
11
10
  end
12
11
 
13
-
14
- def request_host
15
- @env['HTTP_HOST'].split(':').first
16
- end
17
-
18
12
  def call(env)
19
- @env = env
20
- if request_host != @host && !@ignore.include?(request_host)
21
- uri = URI.parse ''
13
+ request = rack_request(env)
14
+
15
+ if request.host != @host && !@ignore.include?(request.host)
16
+ uri = URI.parse request.url
22
17
  uri.host = @host
23
- uri.query = env['QUERY_STRING'] || ''
24
- uri.path = env['REQUEST_PATH'] || ''
25
18
  uri.scheme = @scheme
26
19
 
27
20
  status = 301
@@ -33,5 +26,11 @@ module Rack
33
26
  @app.call(env)
34
27
  end
35
28
  end
29
+
30
+ protected
31
+
32
+ def rack_request(env)
33
+ Rack::Request.new(env)
34
+ end
36
35
  end
37
36
  end
@@ -2,8 +2,8 @@
2
2
  require File.expand_path('../lib/rack/canonical_host', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["Fabrizio Regini"]
6
- gem.email = ["freegenie@gmail.com"]
5
+ gem.authors = ["Fabrizio Regini", "Daniel Vartanov"]
6
+ gem.email = ["freegenie@gmail.com", "dan@vartanov.net"]
7
7
  gem.description = %q{Handle redirect to canonical host}
8
8
  gem.summary = %q{Rack module to redirect to one canonical host and redirect when hitting the app with any other name}
9
9
  gem.homepage = ""
@@ -15,4 +15,5 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Rack::CanonicalHost::VERSION
17
17
  gem.add_development_dependency 'rspec', '~> 2.0'
18
+ gem.add_development_dependency 'rack'
18
19
  end
@@ -33,7 +33,7 @@ describe Rack::CanonicalHost do
33
33
  response = Rack::MockRequest.new(app)
34
34
  .get('/', {
35
35
  'HTTP_HOST' => 'foo.example.org',
36
- 'REQUEST_PATH' => '/login'
36
+ 'PATH_INFO' => '/login'
37
37
  })
38
38
 
39
39
  response.headers['Location'].should =~ /\/login/
@@ -43,7 +43,7 @@ describe Rack::CanonicalHost do
43
43
  response = Rack::MockRequest.new(app)
44
44
  .get('/', {
45
45
  'HTTP_HOST' => 'foo.example.org',
46
- 'REQUEST_PATH' => '/login',
46
+ 'PATH_INFO' => '/login',
47
47
  'QUERY_STRING' => 'a=10&b=20'
48
48
  })
49
49
 
metadata CHANGED
@@ -1,19 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-canonical-hostname
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Fabrizio Regini
9
+ - Daniel Vartanov
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-06-18 00:00:00.000000000Z
13
+ date: 2012-06-19 00:00:00.000000000Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rspec
16
- requirement: &2154510280 !ruby/object:Gem::Requirement
17
+ requirement: &2162166960 !ruby/object:Gem::Requirement
17
18
  none: false
18
19
  requirements:
19
20
  - - ~>
@@ -21,10 +22,22 @@ dependencies:
21
22
  version: '2.0'
22
23
  type: :development
23
24
  prerelease: false
24
- version_requirements: *2154510280
25
+ version_requirements: *2162166960
26
+ - !ruby/object:Gem::Dependency
27
+ name: rack
28
+ requirement: &2162166340 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *2162166340
25
37
  description: Handle redirect to canonical host
26
38
  email:
27
39
  - freegenie@gmail.com
40
+ - dan@vartanov.net
28
41
  executables: []
29
42
  extensions: []
30
43
  extra_rdoc_files: []