rack-www 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/LICENSE +22 -0
  2. data/README.rdoc +16 -0
  3. data/lib/rack/www.rb +29 -0
  4. data/lib/rack-www.rb +1 -0
  5. metadata +83 -0
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2011 Jhimy Fernandes Villar
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,16 @@
1
+ == rack-www
2
+
3
+ Redirects all trafic from http://example.com to http://www.example.com
4
+
5
+ === Installation
6
+
7
+ gem install rack-www #default installation
8
+ gem 'rack-www' #when using bundler
9
+
10
+ === Usage
11
+
12
+ config.middleware.use Rack::WWW
13
+
14
+ === License
15
+
16
+ MIT License. Copyright 2011 Jhimy Fernandes Villar. http://www.stjhimy.com
data/lib/rack/www.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'rack'
2
+ require 'rack/request'
3
+
4
+ module Rack
5
+ class WWW
6
+ def initialize(app, options = {})
7
+ @app = app
8
+ @options = options
9
+ end
10
+
11
+ def call(env)
12
+ status, headers, body = @app.call(env)
13
+ req = Request.new(env)
14
+ host = URI(req.host).to_s
15
+ if already_www?(host)
16
+ [status, headers, body]
17
+ else
18
+ url = URI(req.url).scheme + "://www." + host + URI(req.path).to_s
19
+ headers = headers.merge('Location' => url)
20
+ [301, headers, body]
21
+ end
22
+ end
23
+
24
+ private
25
+ def already_www?(host)
26
+ host.downcase =~ /^(www.)/
27
+ end
28
+ end
29
+ end
data/lib/rack-www.rb ADDED
@@ -0,0 +1 @@
1
+ require 'rack/www'
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-www
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Jhimy Fernandes Villar
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-06 00:00:00 -03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rack
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: " Rack middleware to force redirects to www.\n"
36
+ email: stjhimy@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - lib/rack-www.rb
45
+ - lib/rack/www.rb
46
+ - LICENSE
47
+ - README.rdoc
48
+ has_rdoc: true
49
+ homepage: https://github.com/stjhimy/rack-www
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.5.2
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Force redirects to www.
82
+ test_files: []
83
+