rack-jsonp-tools 0.3.2 → 0.3.3
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/VERSION +1 -1
- data/lib/rack/jsonp/callback.rb +2 -4
- data/lib/rack/jsonp/status_wrapper.rb +2 -4
- data/rack-jsonp-tools.gemspec +2 -2
- data/test/callback_test.rb +16 -1
- data/test/status_wrapper_test.rb +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.3
|
data/lib/rack/jsonp/callback.rb
CHANGED
@@ -16,13 +16,11 @@ module Rack
|
|
16
16
|
# Call original app
|
17
17
|
status, headers, @body = @app.call(env)
|
18
18
|
|
19
|
-
# Callback
|
20
|
-
@pre, @post = "#{callback}(", ")"
|
21
|
-
|
22
19
|
# Fix content length if present
|
23
20
|
content_length = headers["Content-Length"].to_i
|
24
21
|
|
25
|
-
if content_length > 0
|
22
|
+
if (200...300).include?(status) && content_length > 0
|
23
|
+
@pre, @post = "#{callback}(", ")"
|
26
24
|
headers["Content-Length"] = (@pre.size + content_length + @post.size).to_s
|
27
25
|
headers["Content-Type"] = "application/javascript" # Set proper content type as per RFC4329
|
28
26
|
[200, headers, self] # Override status
|
@@ -11,13 +11,11 @@ module Rack
|
|
11
11
|
# Call original app
|
12
12
|
status, headers, @body = @app.call(env)
|
13
13
|
|
14
|
-
# Wrap
|
15
|
-
@pre, @post = '{"body": ', ', "status": ' + status.to_s + '}'
|
16
|
-
|
17
14
|
# Fix content length if present
|
18
15
|
content_length = headers["Content-Length"].to_i
|
19
16
|
|
20
|
-
if content_length > 0
|
17
|
+
if (200...300).include?(status) && content_length > 0
|
18
|
+
@pre, @post = '{"body": ', ', "status": ' + status.to_s + '}'
|
21
19
|
headers["Content-Length"] = (@pre.size + content_length + @post.size).to_s
|
22
20
|
[status, headers, self] # Override status
|
23
21
|
else
|
data/rack-jsonp-tools.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rack-jsonp-tools}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jacek Becela"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-28}
|
13
13
|
s.description = %q{A collection of rack middlewares helping you add JSONP to your app}
|
14
14
|
s.email = %q{jacek.becela@gmail.com}
|
15
15
|
s.files = [
|
data/test/callback_test.rb
CHANGED
@@ -3,7 +3,7 @@ require "rack/jsonp/callback"
|
|
3
3
|
|
4
4
|
class CallbackTest < Test::Unit::TestCase
|
5
5
|
def setup
|
6
|
-
@status =
|
6
|
+
@status = 201
|
7
7
|
@headers = { "Content-Type" => "application/json", "Content-Length" => "2" }
|
8
8
|
@body = "{}"
|
9
9
|
end
|
@@ -36,4 +36,19 @@ class CallbackTest < Test::Unit::TestCase
|
|
36
36
|
}
|
37
37
|
assert_equal expected_body, body
|
38
38
|
end
|
39
|
+
|
40
|
+
test "doesn't touch response if outside of status range 200...300" do
|
41
|
+
env = Rack::MockRequest.env_for("/?_callback=callback")
|
42
|
+
app = Rack::JSONP::Callback.new(lambda { |env| [301, @headers, [@body]] })
|
43
|
+
|
44
|
+
status, headers, iterable = app.call(env)
|
45
|
+
body = ""; iterable.each { |l| body << l }
|
46
|
+
|
47
|
+
assert_equal 301, status
|
48
|
+
assert_equal @headers, {
|
49
|
+
"Content-Type" => "application/json",
|
50
|
+
"Content-Length" => @body.size.to_s
|
51
|
+
}
|
52
|
+
assert_equal @body, body
|
53
|
+
end
|
39
54
|
end
|
data/test/status_wrapper_test.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 3
|
9
|
+
version: 0.3.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jacek Becela
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-06-
|
17
|
+
date: 2010-06-28 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|