deelay 0.3.1 → 0.4.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/README.md +1 -1
- data/lib/deelay/app.rb +31 -8
- data/lib/deelay/version.rb +1 -1
- data/test/test_deelay_app.rb +47 -17
- metadata +2 -2
data/README.md
CHANGED
data/lib/deelay/app.rb
CHANGED
@@ -6,20 +6,43 @@ module Deelay
|
|
6
6
|
register Sinatra::Async
|
7
7
|
|
8
8
|
aget '/:delay' do
|
9
|
-
|
9
|
+
url = parse_query_string(request.query_string)
|
10
|
+
redirect_to url
|
11
|
+
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
aget '/:delay/*' do
|
14
|
+
url = parse_splat(params[:splat].join("/"), request.query_string)
|
15
|
+
redirect_to url
|
14
16
|
end
|
15
17
|
|
16
18
|
private
|
17
19
|
|
18
|
-
def
|
19
|
-
|
20
|
+
def redirect_to(url, delay = 0)
|
21
|
+
EM.add_timer(delay / 1000) do
|
22
|
+
em_async_schedule { redirect url }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_query_string(raw_url)
|
27
|
+
escaped_url = ::URI.unescape(raw_url)
|
28
|
+
raise ArgumentError, "Missing URL" if request.query_string.empty?
|
29
|
+
|
30
|
+
url = (escaped_url =~ /^http:\/\// ? "" : "http://") + escaped_url
|
31
|
+
return url
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse_splat(raw_url, query_string)
|
35
|
+
raise ArgumentError, "Missing URL" if raw_url.empty?
|
36
|
+
|
37
|
+
escaped_url = ::URI.unescape(raw_url)
|
38
|
+
url = escaped_url.sub(/^http:\//, "http://")
|
39
|
+
url = "http://" + url if url !~ /^http:\/\//
|
40
|
+
url << "?" + request.query_string if !request.query_string.empty?
|
41
|
+
return url
|
42
|
+
end
|
20
43
|
|
21
|
-
|
22
|
-
|
44
|
+
def validate(url)
|
45
|
+
raise "Invalid url" if url =~ /(http|https)/
|
23
46
|
end
|
24
47
|
|
25
48
|
# swaps env when testing
|
data/lib/deelay/version.rb
CHANGED
data/test/test_deelay_app.rb
CHANGED
@@ -13,37 +13,67 @@ class TestDeelayApp < MiniTest::Unit::TestCase
|
|
13
13
|
Deelay::App.new
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
get "/10?http://testurl.com"
|
16
|
+
def test_redirect_query_with_scheme
|
17
|
+
get "/10?http://testurl.com/path"
|
18
18
|
em_async_continue
|
19
|
-
assert_equal "http://testurl.com", last_response.location
|
19
|
+
assert_equal "http://testurl.com/path", last_response.location
|
20
20
|
assert_equal 302, last_response.status
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
def test_redirect_query_no_scheme
|
24
|
+
get "/10?testurl.com/path"
|
25
|
+
em_async_continue
|
26
|
+
assert_equal "http://testurl.com/path", last_response.location
|
27
|
+
assert_equal 302, last_response.status
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_redirect_query_with_port
|
31
|
+
get "/10?testurl.com:1234/path"
|
32
|
+
em_async_continue
|
33
|
+
assert_equal "http://testurl.com:1234/path", last_response.location
|
34
|
+
assert_equal 302, last_response.status
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def test_redirect_url_with_scheme
|
39
|
+
get "/10/http://testurl.com/path"
|
40
|
+
em_async_continue
|
41
|
+
assert_equal "http://testurl.com/path", last_response.location
|
42
|
+
assert_equal 302, last_response.status
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_redirect_url_no_scheme
|
46
|
+
get "/10/testurl.com/path"
|
47
|
+
em_async_continue
|
48
|
+
assert_equal "http://testurl.com/path", last_response.location
|
49
|
+
assert_equal 302, last_response.status
|
28
50
|
end
|
29
51
|
|
52
|
+
def test_redirect_url_with_port
|
53
|
+
get "/10/testurl.com:1234"
|
54
|
+
em_async_continue
|
55
|
+
assert_equal "http://testurl.com:1234", last_response.location
|
56
|
+
assert_equal 302, last_response.status
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_redirect_url_with_query
|
60
|
+
get "/10/http://testurl.com/path?query=param"
|
61
|
+
em_async_continue
|
62
|
+
assert_equal "http://testurl.com/path?query=param", last_response.location
|
63
|
+
assert_equal 302, last_response.status
|
64
|
+
end
|
65
|
+
|
66
|
+
|
30
67
|
def test_no_query
|
31
68
|
get "/10"
|
32
|
-
assert_raises(
|
69
|
+
assert_raises(ArgumentError) do
|
33
70
|
em_async_continue(0.1)
|
34
71
|
end
|
35
72
|
end
|
36
73
|
|
37
74
|
def test_no_link
|
38
75
|
get "/10?"
|
39
|
-
assert_raises(
|
40
|
-
em_async_continue(0.1)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_no_scheme_link
|
45
|
-
get "/10?testurl.com"
|
46
|
-
assert_raises(RuntimeError) do
|
76
|
+
assert_raises(ArgumentError) do
|
47
77
|
em_async_continue(0.1)
|
48
78
|
end
|
49
79
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deelay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -46,7 +46,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
46
|
version: '0'
|
47
47
|
segments:
|
48
48
|
- 0
|
49
|
-
hash:
|
49
|
+
hash: -2051873546142903568
|
50
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|