with-or-without-www 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT_LICENCE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011 Mickael Riga
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ > I can live with or without WWW...
2
+ – Bono from U2
3
+
4
+ WithOrWithoutWWW
5
+ ================
6
+
7
+ This Rack middleware is ridiculously simple.
8
+ It just add or remove `www` from your host name depending on what you want.
9
+ This is good for SEO to gather everything under one host name.
10
+
11
+ Normally, this is done in your vhost settings, which means that this middleware is for
12
+ when you don't have access to vhosts settings like on Heroku for example.
13
+
14
+ In your rack stack, use it:
15
+
16
+ use WithOrWithoutWWW
17
+
18
+ And then it adds `www` if somebody tries to reach the website without it.
19
+ Whereas:
20
+
21
+ use WithOrWithoutWWW, false
22
+
23
+ Will do the opposite.
24
+ It will remove the `www` from your host name.
25
+
26
+ I almost feel guilty to make a Gem for that.
27
+
28
+ Thx for reading,
29
+ Mig
@@ -0,0 +1,13 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'with-or-without-www'
3
+ s.version = "0.0.1"
4
+ s.platform = Gem::Platform::RUBY
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
+ 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."
7
+ s.files = `git ls-files`.split("\n").sort
8
+ #s.test_files = ['spec.rb']
9
+ s.require_path = '.'
10
+ s.author = "Mickael Riga"
11
+ s.email = "mig@mypeplum.com"
12
+ s.homepage = "http://github.com/mig-hub/with-or-without-www"
13
+ end
@@ -0,0 +1,20 @@
1
+ class WithOrWithoutWWW
2
+
3
+ def initialize(app, with=true)
4
+ @app, @with = app, with
5
+ end
6
+
7
+ def call(env)
8
+ req = Rack::Request.new(env)
9
+ if !@with && req.host[/^www./]
10
+ [301, {"Location" => req.url.sub("//www.", "//")}, self]
11
+ elsif @with && !req.host[/^www./]
12
+ [301, {"Location" => req.url.sub("//", "//www.")}, self]
13
+ else
14
+ @app.call(env)
15
+ end
16
+ end
17
+
18
+ def each(&block); end
19
+
20
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: with-or-without-www
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Mickael Riga
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-09 00:00:00 +00:00
19
+ default_executable:
20
+ 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.
23
+ email: mig@mypeplum.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - MIT_LICENCE
32
+ - README.md
33
+ - with_or_without_www.gemspec
34
+ - with_or_without_www.rb
35
+ has_rdoc: true
36
+ homepage: http://github.com/mig-hub/with-or-without-www
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - .
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ 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
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.4.2
66
+ signing_key:
67
+ 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.
69
+ test_files: []
70
+