rack-jsonr 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/rack/jsonr/jsonr.rb +14 -9
- data/lib/rack/jsonr/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzBlYjQzNDI1OWI4Njk0NDE4NWQ2NzUwNTAxZTBhZTE5MWNhMGJiZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Y2YxMTA2OTc2NjM0MjBkMzhhOGQ0MTQyNGY2YjliYTM3YmE4MjE4NA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MjljNjk5MmE2YjlhODhjOTI1ZDJiZTVkMzYzYWZmNWM4MzE0NjFiYjA4Zjhk
|
10
|
+
MWJlOTgzNDI1MzkyZmZiMzMyNmY0YWJlMzhhYjZhNDlhMWM0YmUxM2M2OWY4
|
11
|
+
YzI2OTA5Zjc5MTZlY2Y3YTdiYzYzZGRiNWM4MTc2M2EzOTgzNTY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTBkMGM1M2ExN2JlMmZmZDRmNWU0MTRiYjNjYTU0YzQ2MjI3YjQ4MTY5Mzcz
|
14
|
+
YjgzNTM1ZTk4MzFhN2I2ZGM0NDBhNGMzZWQ2MWVjOGNhZWNiYjU2Y2MzNjQw
|
15
|
+
MThiYTVmYjk3ZDcwOGYxZmVkYmYxOGNiM2YwNmRmYWE0MDhmYzg=
|
data/lib/rack/jsonr/jsonr.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
require 'rack'
|
2
2
|
|
3
3
|
module Rack
|
4
|
-
# A Rack middleware for providing JSONP in a usable way - accepts GET/POST/PUT/DELETE verbs and http status and
|
5
|
-
# headers are readable from the body.
|
6
|
-
#
|
7
|
-
# Based on Rack-JSONP by Flinn Mueller (http://actsasflinn.com/)
|
8
|
-
#
|
9
4
|
class JSONR
|
5
|
+
# Based on Rack-JSONP by Flinn Mueller (http://actsasflinn.com/)
|
10
6
|
include Rack::Utils
|
11
7
|
|
12
|
-
|
8
|
+
HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS PATCH)
|
9
|
+
METHOD_OVERRIDE_PARAM_KEY = '_method'.freeze
|
10
|
+
HTTP_METHOD_OVERRIDE_HEADER = 'HTTP_X_HTTP_METHOD_OVERRIDE'.freeze
|
11
|
+
|
12
|
+
def initialize(app, options={})
|
13
|
+
@options = options
|
13
14
|
@app = app
|
14
15
|
end
|
15
16
|
|
@@ -26,11 +27,15 @@ module Rack
|
|
26
27
|
request = Rack::Request.new(env)
|
27
28
|
params = request.params
|
28
29
|
|
29
|
-
if is_jsonp_request?(request)
|
30
|
-
|
30
|
+
if is_jsonp_request?(request) or @options[:method_override] == :all
|
31
|
+
method_override = (params[METHOD_OVERRIDE_PARAM_KEY] || env[HTTP_METHOD_OVERRIDE_HEADER]).to_s.upcase
|
32
|
+
if HTTP_METHODS.include?(method_override)
|
33
|
+
env['rack.jsonr_method_override.original_method'] = env['REQUEST_METHOD']
|
34
|
+
env['REQUEST_METHOD'] = method_override
|
35
|
+
end
|
31
36
|
end
|
32
37
|
|
33
|
-
if is_jsonp_request?(request)
|
38
|
+
if is_jsonp_request?(request)
|
34
39
|
response = format_jsonp(request.params.delete('callback'), status, headers, response)
|
35
40
|
status = 200
|
36
41
|
|
data/lib/rack/jsonr/version.rb
CHANGED