rack-jsonp-middleware 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +14 -4
  2. data/lib/rack/jsonp.rb +5 -2
  3. metadata +2 -2
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # rack-jsonp-middleware - ![Travis CI Status](http://travis-ci.org/robertodecurnex/rack-jsonp-middleware.png) - ![Gemnasium Dependencies Status](https://gemnasium.com/robertodecurnex/rack-jsonp-middleware.png)
1
+ # rack-jsonp-middleware
2
+ ![Travis CI Status](https://travis-ci.org/robertodecurnex/rack-jsonp-middleware.png) - ![Gemnasium Dependencies Status](https://gemnasium.com/robertodecurnex/rack-jsonp-middleware.png) - [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/robertodecurnex/rack-jsonp-middleware)
2
3
 
3
4
  Rack middleware that turns all .jsonp requests into a jsonp response.
4
5
 
@@ -63,19 +64,28 @@ You can also clone the project with Git by running:
63
64
 
64
65
  ## Examples
65
66
 
66
- Given that http://domain.com/action.json returns the following:
67
+ Given that http://domain.com/action.json returns:
68
+
67
69
  {"key":"value"}
70
+
68
71
  With the following Content-Type:
72
+
69
73
  application/json
70
74
 
71
- Then http://domain.com/action.jsonp?callback=J50Npi.success will return the following:
75
+ Then http://domain.com/action.jsonp?callback=J50Npi.success will return:
76
+
72
77
  J50Npi.success({"key":"value"})
78
+
73
79
  With the following Content-Type:
80
+
74
81
  application/javascript
75
82
 
76
- But http://domain.com/action.json?callback=J50Npi.sucess will still returns the following:
83
+ But http://domain.com/action.json?callback=J50Npi.sucess will still return:
84
+
77
85
  {"key":"value"}
86
+
78
87
  With the following Content-Type:
88
+
79
89
  application/json
80
90
 
81
91
  # Security
data/lib/rack/jsonp.rb CHANGED
@@ -1,3 +1,6 @@
1
+
2
+ require 'pathname'
3
+
1
4
  module Rack
2
5
 
3
6
  class JSONP
@@ -14,7 +17,7 @@ module Rack
14
17
  return [400,{},[]] if requesting_jsonp && !self.valid_callback?(callback)
15
18
 
16
19
  if requesting_jsonp
17
- env['PATH_INFO'].sub!(/\.jsonp/i, '.json')
20
+ env['PATH_INFO'] = env['PATH_INFO'].sub(/\.jsonp/i, '.json')
18
21
  env['REQUEST_URI'] = env['PATH_INFO']
19
22
  end
20
23
 
@@ -25,7 +28,7 @@ module Rack
25
28
  body.each { |s| json << s }
26
29
  body = ["#{callback}(#{json});"]
27
30
  headers['Content-Length'] = Rack::Utils.bytesize(body[0]).to_s
28
- headers['Content-Type'].sub!(/^[^;]+(;?)/, "#{MIME_TYPE}\\1")
31
+ headers['Content-Type'] = headers['Content-Type'].sub(/^[^;]+(;?)/, "#{MIME_TYPE}\\1")
29
32
  end
30
33
 
31
34
  [status, headers, body]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-jsonp-middleware
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-12 00:00:00.000000000 Z
12
+ date: 2012-10-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack