rack-jsonp-middleware 0.0.7 → 0.0.8
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/README.md +14 -4
- data/lib/rack/jsonp.rb +5 -2
- metadata +2 -2
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# rack-jsonp-middleware
|
1
|
+
# rack-jsonp-middleware
|
2
|
+
 -  - [](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
|
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
|
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
|
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
|
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
|
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.
|
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-
|
12
|
+
date: 2012-10-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|