rack-jsonp-tools 0.3.0 → 0.3.2
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 +8 -7
- data/lib/rack/jsonp/status_wrapper.rb +9 -6
- data/rack-jsonp-tools.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
data/lib/rack/jsonp/callback.rb
CHANGED
@@ -20,14 +20,15 @@ module Rack
|
|
20
20
|
@pre, @post = "#{callback}(", ")"
|
21
21
|
|
22
22
|
# Fix content length if present
|
23
|
-
|
24
|
-
headers["Content-Length"] = (@pre.size + content_length.to_i + @post.size).to_s
|
25
|
-
end
|
26
|
-
|
27
|
-
# Set proper content type as per RFC4329
|
28
|
-
headers["Content-Type"] = "application/javascript"
|
23
|
+
content_length = headers["Content-Length"].to_i
|
29
24
|
|
30
|
-
|
25
|
+
if content_length > 0
|
26
|
+
headers["Content-Length"] = (@pre.size + content_length + @post.size).to_s
|
27
|
+
headers["Content-Type"] = "application/javascript" # Set proper content type as per RFC4329
|
28
|
+
[200, headers, self] # Override status
|
29
|
+
else
|
30
|
+
[status, headers, @body]
|
31
|
+
end
|
31
32
|
else
|
32
33
|
@app.call(env)
|
33
34
|
end
|
@@ -2,8 +2,8 @@ module Rack
|
|
2
2
|
module JSONP
|
3
3
|
|
4
4
|
class StatusWrapper
|
5
|
-
def initialize(app
|
6
|
-
@app
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
7
|
end
|
8
8
|
|
9
9
|
def call(env)
|
@@ -15,11 +15,14 @@ module Rack
|
|
15
15
|
@pre, @post = '{"body": ', ', "status": ' + status.to_s + '}'
|
16
16
|
|
17
17
|
# Fix content length if present
|
18
|
-
|
19
|
-
headers["Content-Length"] = (@pre.size + content_length.to_i + @post.size).to_s
|
20
|
-
end
|
18
|
+
content_length = headers["Content-Length"].to_i
|
21
19
|
|
22
|
-
|
20
|
+
if content_length > 0
|
21
|
+
headers["Content-Length"] = (@pre.size + content_length + @post.size).to_s
|
22
|
+
[status, headers, self] # Override status
|
23
|
+
else
|
24
|
+
[status, headers, @body]
|
25
|
+
end
|
23
26
|
else
|
24
27
|
@app.call(env)
|
25
28
|
end
|
data/rack-jsonp-tools.gemspec
CHANGED