rewritten 0.14.2 → 0.15.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.
- checksums.yaml +4 -4
- data/HISTORY.rdoc +4 -0
- data/lib/rack/url.rb +18 -1
- data/lib/rewritten/version.rb +1 -1
- data/test/rack/rewritten_url_test.rb +20 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 452e88a0bbdf356f472e86034e0df828f4708899
|
4
|
+
data.tar.gz: bb3f1342257f6aa9414aada49a6ad2af7daf4af8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5f725ac82a9353f1eaff6dfdb01655dde86ef5e1e3b17df701dad7215aa4d417d26ce5633195d5ed2cd0a35648655b0daba426fd84d7c89bea91f5ccd94fcbb
|
7
|
+
data.tar.gz: c4fe89affbe1216585006c25dc3cede93be62ffb4ab839f8bd053185e2c2f14a4200b77e873a0f26413257f6989ee3e928e2e379244bd6f24a885eb3024312f6
|
data/HISTORY.rdoc
CHANGED
data/lib/rack/url.rb
CHANGED
@@ -6,14 +6,25 @@ module Rack
|
|
6
6
|
|
7
7
|
class Url
|
8
8
|
|
9
|
+
attr_accessor :base_url
|
10
|
+
|
9
11
|
def initialize(app, &block)
|
10
12
|
@app = app
|
11
13
|
@translate_backwards = false
|
12
14
|
@downcase_before_lookup = false
|
13
15
|
@translate_partial = false
|
16
|
+
@base_url = ''
|
14
17
|
instance_eval(&block) if block_given?
|
15
18
|
end
|
16
19
|
|
20
|
+
def is_internal_target?(url)
|
21
|
+
url.nil? or url.start_with?('/') or url.start_with?(@base_url)
|
22
|
+
end
|
23
|
+
|
24
|
+
def is_external_target?(url)
|
25
|
+
!is_internal_target?(url)
|
26
|
+
end
|
27
|
+
|
17
28
|
def call(env)
|
18
29
|
req = Rack::Request.new(env)
|
19
30
|
|
@@ -22,7 +33,13 @@ module Rack
|
|
22
33
|
path = "#{subdomain}#{req.path_info}"
|
23
34
|
path.downcase! if downcase_before_lookup?
|
24
35
|
|
25
|
-
|
36
|
+
target_url = ::Rewritten.translate(path)
|
37
|
+
|
38
|
+
if is_external_target?(target_url)
|
39
|
+
r = Rack::Response.new
|
40
|
+
r.redirect(target_url, 301)
|
41
|
+
r.finish
|
42
|
+
elsif ::Rewritten.includes?(path.chomp("/")) or backwards=( translate_backwards? && ::Rewritten.exist_translation_for?(path) )
|
26
43
|
|
27
44
|
to = ::Rewritten.includes?(path.chomp("/")) || path
|
28
45
|
|
data/lib/rewritten/version.rb
CHANGED
@@ -61,6 +61,26 @@ describe Rack::Rewritten::Url do
|
|
61
61
|
ret[0].must_equal 200
|
62
62
|
end
|
63
63
|
|
64
|
+
describe 'external redirection' do
|
65
|
+
|
66
|
+
before {
|
67
|
+
@app = MiniTest::Mock.new
|
68
|
+
@rack = Rack::Rewritten::Url.new(@app) do |config|
|
69
|
+
config.base_url = 'http://www.example.org'
|
70
|
+
end
|
71
|
+
|
72
|
+
Rewritten.add_translation '/external/target', 'http://www.external.com'
|
73
|
+
}
|
74
|
+
|
75
|
+
it "must redirect to external target" do
|
76
|
+
ret = @rack.call request_url('/external/target')
|
77
|
+
@app.verify
|
78
|
+
ret[0].must_equal 301
|
79
|
+
ret[1]['Location'].must_equal "http://www.external.com"
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
64
84
|
describe "partial translation" do
|
65
85
|
|
66
86
|
before do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rewritten
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kai Rubarth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis-namespace
|