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 CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.3.3
@@ -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
@@ -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.2"
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-25}
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 = [
@@ -3,7 +3,7 @@ require "rack/jsonp/callback"
3
3
 
4
4
  class CallbackTest < Test::Unit::TestCase
5
5
  def setup
6
- @status = 401
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
@@ -3,7 +3,7 @@ require "rack/jsonp/status_wrapper"
3
3
 
4
4
  class StatusWrapperTest < Test::Unit::TestCase
5
5
  def setup
6
- @status = 401
6
+ @status = 201
7
7
  @body = "{ number: 666 }"
8
8
  @headers = { "Content-Type" => "application/json", "Content-Length" => @body.size }
9
9
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 2
9
- version: 0.3.2
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-25 00:00:00 +02:00
17
+ date: 2010-06-28 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency