rack-strip-www 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack/strip-www.rb +3 -34
- metadata +28 -10
data/lib/rack/strip-www.rb
CHANGED
@@ -1,38 +1,7 @@
|
|
1
|
-
require 'rack'
|
2
|
-
require 'uri'
|
1
|
+
require 'rack/normalize-domain'
|
3
2
|
|
4
|
-
class Rack::StripWWW
|
3
|
+
class Rack::StripWWW < Rack::NormalizeDomain
|
5
4
|
def initialize(app)
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def call(env)
|
10
|
-
if env['REQUEST_METHOD'] != 'GET'
|
11
|
-
@app.call(env)
|
12
|
-
else
|
13
|
-
host = env['HTTP_HOST'] || env['SERVER_NAME']
|
14
|
-
stripped_host = strip_www(host)
|
15
|
-
|
16
|
-
if stripped_host == host
|
17
|
-
@app.call(env)
|
18
|
-
else
|
19
|
-
scheme = env['rack.url_scheme']
|
20
|
-
path = env['PATH_INFO']
|
21
|
-
path = '' if path == '/'
|
22
|
-
query = env['QUERY_STRING']
|
23
|
-
query = '?' + query unless query == ''
|
24
|
-
new_url = "#{scheme}://#{stripped_host}#{path}#{query}"
|
25
|
-
[301, { 'Location' => new_url }, new_url]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def strip_www(host)
|
31
|
-
case host
|
32
|
-
when /^www\.(([^.]+\.){1,2}[a-z]+)$/
|
33
|
-
$1
|
34
|
-
else
|
35
|
-
host
|
36
|
-
end
|
5
|
+
super app, :strip_www
|
37
6
|
end
|
38
7
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-strip-www
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
+
- 3
|
8
9
|
- 0
|
9
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Daniel Brockman
|
@@ -14,10 +15,24 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
date: 2011-05-25 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rack-normalize-domain
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 29
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- 1
|
33
|
+
version: 0.0.1
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
21
36
|
description:
|
22
37
|
email:
|
23
38
|
- daniel@brockman.se
|
@@ -29,8 +44,7 @@ extra_rdoc_files: []
|
|
29
44
|
|
30
45
|
files:
|
31
46
|
- lib/rack/strip-www.rb
|
32
|
-
|
33
|
-
homepage: http://github.com/dbrock/rack-strip-www
|
47
|
+
homepage: http://github.com/dbrock/rack-normalize-domain
|
34
48
|
licenses: []
|
35
49
|
|
36
50
|
post_install_message:
|
@@ -39,23 +53,27 @@ rdoc_options: []
|
|
39
53
|
require_paths:
|
40
54
|
- lib
|
41
55
|
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
42
57
|
requirements:
|
43
58
|
- - ">="
|
44
59
|
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
45
61
|
segments:
|
46
62
|
- 0
|
47
63
|
version: "0"
|
48
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
49
66
|
requirements:
|
50
67
|
- - ">="
|
51
68
|
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
52
70
|
segments:
|
53
71
|
- 0
|
54
72
|
version: "0"
|
55
73
|
requirements: []
|
56
74
|
|
57
75
|
rubyforge_project:
|
58
|
-
rubygems_version: 1.
|
76
|
+
rubygems_version: 1.7.2
|
59
77
|
signing_key:
|
60
78
|
specification_version: 3
|
61
79
|
summary: Rack middleware that redirects www.example.com to example.com.
|