rack-jsonp-middleware 0.0.1 → 0.0.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.
Files changed (2) hide show
  1. data/lib/rack/jsonp.rb +12 -9
  2. metadata +19 -3
data/lib/rack/jsonp.rb CHANGED
@@ -1,30 +1,33 @@
1
1
  module Rack
2
+
2
3
  class JSONP
3
- include Rack::Utils
4
4
 
5
5
  def initialize(app)
6
6
  @app = app
7
7
  end
8
8
 
9
-
10
9
  def call(env)
11
10
  request = Rack::Request.new(env)
12
- requesting_jsonp = Pathname(request.env['REQUEST_PATH']).extname =~ /^\.jsonp$/i
11
+ requesting_jsonp = Pathname(request.env['PATH_INFO']).extname =~ /^\.jsonp$/i
13
12
  callback = request.params['callback']
14
13
 
15
14
  return [400,{},[]] if requesting_jsonp && !callback
16
15
 
17
- env['REQUEST_URI'].sub!(/\.jsonp/i, '.json') if requesting_jsonp
16
+ env['PATH_INFO'].sub!(/\.jsonp/i, '.json') if requesting_jsonp
18
17
 
19
- status, headers, response = @app.call(env)
18
+ status, headers, body = @app.call(env)
20
19
 
21
20
  if requesting_jsonp
22
- response.body = "#{callback}(#{response.body});"
23
- headers['Content-Length'] = response.body.length.to_s
21
+ json = ""
22
+ body.each { |s| json << s }
23
+ body = ["#{callback}(#{json});"]
24
+ headers['Content-Length'] = body[0].length.to_s
24
25
  headers['Content-Type'] = 'application/javascript'
25
26
  end
26
27
 
27
- [status, headers, response]
28
+ [status, headers, body]
28
29
  end
30
+
29
31
  end
30
- end
32
+
33
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-jsonp-middleware
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Roberto Decurnex
@@ -32,6 +32,22 @@ dependencies:
32
32
  version: "0"
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 27
44
+ segments:
45
+ - 1
46
+ - 3
47
+ - 0
48
+ version: 1.3.0
49
+ type: :development
50
+ version_requirements: *id002
35
51
  description: A Rack JSONP middleware
36
52
  email: nex.development@gmail.com
37
53
  executables: []