with-or-without-www 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -11,7 +11,15 @@ This is good for SEO to gather everything under one host name.
11
11
  Normally, this is done in your vhost settings, which means that this middleware is for
12
12
  when you don't have access to vhosts settings like on Heroku for example.
13
13
 
14
- In your rack stack, use it:
14
+ Install it:
15
+
16
+ sudo gem install with-or-without-www
17
+
18
+ Require it in your Rackup file:
19
+
20
+ require 'with_or_without_www'
21
+
22
+ Use it:
15
23
 
16
24
  use WithOrWithoutWWW
17
25
 
@@ -23,6 +31,9 @@ Whereas:
23
31
  Will do the opposite.
24
32
  It will remove the `www` from your host name.
25
33
 
34
+ A third argument can be passed and is an array with domain names to exclude (on which the middleware will have no effect).
35
+ The default value is `['localhost']`.
36
+
26
37
  I almost feel guilty to make a Gem for that.
27
38
 
28
39
  Thx for reading,
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'with-or-without-www'
3
- s.version = "0.0.1"
3
+ s.version = "0.0.2"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.summary = "For Heroku users who want to systematically remove or add `www` from their host names. This rack middleware is for them. Go in peace."
6
6
  s.description = "For Heroku users who want to systematically remove or add `www` from their host names. So that you have only one host which is better for SEO."
@@ -1,15 +1,16 @@
1
1
  class WithOrWithoutWWW
2
2
 
3
- def initialize(app, with=true)
4
- @app, @with = app, with
3
+ def initialize(app, with=true, excluded=['localhost'])
4
+ @app, @with, @excluded = app, with, excluded
5
5
  end
6
6
 
7
7
  def call(env)
8
8
  req = Rack::Request.new(env)
9
+ return @app.call(env) if @excluded.include?(req.host)
9
10
  if !@with && req.host[/^www./]
10
- [301, {"Location" => req.url.sub("//www.", "//")}, self]
11
+ [301, {"Location" => req.url.sub("//www.", "//"), 'Content-Type'=>'text/html'}, self]
11
12
  elsif @with && !req.host[/^www./]
12
- [301, {"Location" => req.url.sub("//", "//www.")}, self]
13
+ [301, {"Location" => req.url.sub("//", "//www."), 'Content-Type'=>'text/html'}, self]
13
14
  else
14
15
  @app.call(env)
15
16
  end
metadata CHANGED
@@ -1,70 +1,50 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: with-or-without-www
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Mickael Riga
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-11-09 00:00:00 +00:00
19
- default_executable:
12
+ date: 2012-12-04 00:00:00.000000000 Z
20
13
  dependencies: []
21
-
22
- description: For Heroku users who want to systematically remove or add `www` from their host names. So that you have only one host which is better for SEO.
14
+ description: For Heroku users who want to systematically remove or add `www` from
15
+ their host names. So that you have only one host which is better for SEO.
23
16
  email: mig@mypeplum.com
24
17
  executables: []
25
-
26
18
  extensions: []
27
-
28
19
  extra_rdoc_files: []
29
-
30
- files:
20
+ files:
31
21
  - MIT_LICENCE
32
22
  - README.md
33
23
  - with_or_without_www.gemspec
34
24
  - with_or_without_www.rb
35
- has_rdoc: true
36
25
  homepage: http://github.com/mig-hub/with-or-without-www
37
26
  licenses: []
38
-
39
27
  post_install_message:
40
28
  rdoc_options: []
41
-
42
- require_paths:
29
+ require_paths:
43
30
  - .
44
- required_ruby_version: !ruby/object:Gem::Requirement
31
+ required_ruby_version: !ruby/object:Gem::Requirement
45
32
  none: false
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- hash: 3
50
- segments:
51
- - 0
52
- version: "0"
53
- required_rubygems_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
38
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
62
43
  requirements: []
63
-
64
44
  rubyforge_project:
65
- rubygems_version: 1.4.2
45
+ rubygems_version: 1.8.23
66
46
  signing_key:
67
47
  specification_version: 3
68
- summary: For Heroku users who want to systematically remove or add `www` from their host names. This rack middleware is for them. Go in peace.
48
+ summary: For Heroku users who want to systematically remove or add `www` from their
49
+ host names. This rack middleware is for them. Go in peace.
69
50
  test_files: []
70
-