rack-www 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +5 -0
- data/lib/rack/www.rb +19 -15
- metadata +4 -4
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 1.2
|
2
|
+
* Redirects to the right url without calling the app
|
3
|
+
* Keep the path when redirecting
|
4
|
+
* Keep the query string when redirecting
|
5
|
+
* Added more tests
|
1
6
|
== 1.1
|
2
7
|
* Added possibility to redirects with www or without www.
|
3
8
|
* Added possibility to set a param :message to show while redirecting.
|
data/lib/rack/www.rb
CHANGED
@@ -11,33 +11,37 @@ module Rack
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def call(env)
|
14
|
-
|
15
|
-
|
16
|
-
host = URI(req.host).to_s
|
17
|
-
if (already_www?(host) && @www == true) || (!already_www?(host) && @www == false)
|
18
|
-
[status, headers, @message || body]
|
14
|
+
if (already_www?(env) && @www == true) || (!already_www?(env) && @www == false)
|
15
|
+
status, headers, body = @app.call(env)
|
19
16
|
else
|
20
|
-
url = prepare_url(
|
21
|
-
headers =
|
22
|
-
[301, headers, @message ||
|
17
|
+
url = prepare_url(env)
|
18
|
+
headers = {"Content-Type" => "text/html", "location" => url}
|
19
|
+
[301, headers, @message || ""]
|
23
20
|
end
|
24
21
|
end
|
25
22
|
|
26
23
|
private
|
27
|
-
def already_www?(
|
28
|
-
|
24
|
+
def already_www?(env)
|
25
|
+
env["HTTP_HOST"].downcase =~ /^(www.)/
|
29
26
|
end
|
30
27
|
|
31
|
-
def prepare_url(
|
32
|
-
scheme =
|
33
|
-
host =
|
34
|
-
path =
|
28
|
+
def prepare_url(env)
|
29
|
+
scheme = env["rack.url_scheme"]
|
30
|
+
host = env["SERVER_NAME"].gsub(/^(www.)/, "")
|
31
|
+
path = env["PATH_INFO"].to_s
|
32
|
+
|
33
|
+
if env["QUERY_STRING"].empty?
|
34
|
+
query_string = ""
|
35
|
+
else
|
36
|
+
query_string = "?" + env["QUERY_STRING"]
|
37
|
+
end
|
38
|
+
|
35
39
|
if @www == true
|
36
40
|
host = "://www." + host
|
37
41
|
else
|
38
42
|
host = "://" + host
|
39
43
|
end
|
40
|
-
scheme + host + path
|
44
|
+
scheme + host + path + query_string
|
41
45
|
end
|
42
46
|
end
|
43
47
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-www
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jhimy Fernandes Villar
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-17 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|