rack-jsonp-middleware 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +36 -2
- data/lib/rack/jsonp.rb +9 -3
- metadata +60 -63
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# rack-jsonp-middleware
|
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)
|
2
2
|
|
3
3
|
A Rack JSONP middleware
|
4
4
|
|
@@ -16,14 +16,48 @@ Btw, don't forget to give a try to [J50Nπ](https://github.com/robertodecurnex/J
|
|
16
16
|
|
17
17
|
Roberto Decurnex (nex.development@gmail.com)
|
18
18
|
|
19
|
+
## Contributors
|
20
|
+
|
21
|
+
* [rwilcox](https://github.com/rwilcox "rwilcox profile")
|
22
|
+
* [amiel](https://github.com/amiel "amiel profile")
|
23
|
+
|
19
24
|
## Install
|
20
25
|
|
21
26
|
If you are using Bundler you can easily add the following line to your Gemfile:
|
27
|
+
|
22
28
|
gem 'rack-jsonp-middleware'
|
23
29
|
|
24
30
|
Or you can just install it as a ruby gem by running:
|
31
|
+
|
25
32
|
$ gem install rack-jsonp-middleware
|
26
33
|
|
34
|
+
## Configuration
|
35
|
+
|
36
|
+
### Rails 3
|
37
|
+
|
38
|
+
In your `config/application.rb` file add:
|
39
|
+
|
40
|
+
require 'rack/jsonp'
|
41
|
+
|
42
|
+
And, within the config block:
|
43
|
+
|
44
|
+
config.middleware.use Rack::JSONP
|
45
|
+
|
46
|
+
Here is an exelent example of this - [Rails 3 Configuration Example](https://github.com/rwilcox/rack_jsonp_example/commit/809c2e3d4470b694ba1a98c09f2aa07115f433e5 "Rails 3 Configuration Example")
|
47
|
+
|
48
|
+
Thank you [rwilcox](https://github.com/rwilcox "rwilcox profile")!
|
49
|
+
|
50
|
+
### Rails 2
|
51
|
+
|
52
|
+
Same as for Rails 3 but modifying the `config/environment.rb` file instead.
|
53
|
+
|
54
|
+
### Rack Apps
|
55
|
+
|
56
|
+
In your `config.ru` file add the following lines:
|
57
|
+
|
58
|
+
require 'rack/jsonp'
|
59
|
+
use Rack::JSONP
|
60
|
+
|
27
61
|
## Download
|
28
62
|
|
29
63
|
You can also clone the project with Git by running:
|
@@ -39,7 +73,7 @@ With the following Content-Type:
|
|
39
73
|
Then http://domain.com/action.jsonp?callback=J50Npi.success will return the following:
|
40
74
|
J50Npi.success({"key":"value"})
|
41
75
|
With the following Content-Type:
|
42
|
-
|
76
|
+
application/javascript
|
43
77
|
|
44
78
|
But http://domain.com/action.json?callback=J50Npi.sucess will still returns the following:
|
45
79
|
{"key":"value"}
|
data/lib/rack/jsonp.rb
CHANGED
@@ -17,20 +17,26 @@ module Rack
|
|
17
17
|
env['PATH_INFO'].sub!(/\.jsonp/i, '.json')
|
18
18
|
env['REQUEST_URI'] = env['PATH_INFO']
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
status, headers, body = @app.call(env)
|
22
22
|
|
23
23
|
if requesting_jsonp && headers['Content-Type'] && headers['Content-Type'].match(/application\/json/i)
|
24
24
|
json = ""
|
25
25
|
body.each { |s| json << s }
|
26
26
|
body = ["#{callback}(#{json});"]
|
27
|
-
headers['Content-Length'] = body[0].
|
28
|
-
headers['Content-Type'] = 'application/javascript'
|
27
|
+
headers['Content-Length'] = Rack::Utils.bytesize(body[0]).to_s
|
28
|
+
headers['Content-Type'] = force_mime_type(headers['Content-Type'], 'application/javascript')
|
29
29
|
end
|
30
30
|
|
31
31
|
[status, headers, body]
|
32
32
|
end
|
33
33
|
|
34
|
+
def force_mime_type(content_type, mime_type)
|
35
|
+
content_type_parts = (content_type || '').split(/;/)
|
36
|
+
content_type_parts[0] = mime_type
|
37
|
+
content_type_parts.join(';')
|
38
|
+
end
|
39
|
+
|
34
40
|
end
|
35
41
|
|
36
42
|
end
|
metadata
CHANGED
@@ -1,97 +1,94 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-jsonp-middleware
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 5
|
10
|
-
version: 0.0.5
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Roberto Decurnex
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-07-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: rack
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :runtime
|
34
|
-
|
35
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
36
31
|
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.3.0
|
38
|
+
type: :development
|
37
39
|
prerelease: false
|
38
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
41
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
hash: 27
|
44
|
-
segments:
|
45
|
-
- 1
|
46
|
-
- 3
|
47
|
-
- 0
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
48
45
|
version: 1.3.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
49
54
|
type: :development
|
50
|
-
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
51
62
|
description: A Rack JSONP middleware
|
52
63
|
email: nex.development@gmail.com
|
53
64
|
executables: []
|
54
|
-
|
55
65
|
extensions: []
|
56
|
-
|
57
66
|
extra_rdoc_files: []
|
58
|
-
|
59
|
-
files:
|
67
|
+
files:
|
60
68
|
- README.md
|
61
69
|
- lib/rack/jsonp.rb
|
62
|
-
has_rdoc: true
|
63
70
|
homepage: http://robertodecurnex.github.com/rack-jsonp-middleware
|
64
71
|
licenses: []
|
65
|
-
|
66
72
|
post_install_message:
|
67
73
|
rdoc_options: []
|
68
|
-
|
69
|
-
require_paths:
|
74
|
+
require_paths:
|
70
75
|
- lib
|
71
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
77
|
none: false
|
73
|
-
requirements:
|
74
|
-
- -
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
|
77
|
-
|
78
|
-
- 0
|
79
|
-
version: "0"
|
80
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
83
|
none: false
|
82
|
-
requirements:
|
83
|
-
- -
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
|
86
|
-
segments:
|
87
|
-
- 0
|
88
|
-
version: "0"
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
89
88
|
requirements: []
|
90
|
-
|
91
89
|
rubyforge_project:
|
92
|
-
rubygems_version: 1.
|
90
|
+
rubygems_version: 1.8.24
|
93
91
|
signing_key:
|
94
92
|
specification_version: 3
|
95
93
|
summary: rack-jsonp-middleware-0.0.5
|
96
94
|
test_files: []
|
97
|
-
|