rack-jsonp-tools 0.3.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.2
@@ -20,14 +20,15 @@ module Rack
20
20
  @pre, @post = "#{callback}(", ")"
21
21
 
22
22
  # Fix content length if present
23
- if content_length = headers["Content-Length"]
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
- [200, headers, self] # Override status
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, callback_param = "_callback")
6
- @app, @callback_param = app, callback_param
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
- if content_length = headers["Content-Length"]
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
- [status, headers, self]
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rack-jsonp-tools}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.2"
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"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 0
9
- version: 0.3.0
8
+ - 2
9
+ version: 0.3.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jacek Becela