rack-jsonr 0.2.0 → 0.2.1
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 +16 -12
- 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
|
+
NDJiYzFiMzQ2NTQ3OWUxZjYzOTEzN2ZjNTY2YjI2MWI4YzFiNmJjOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjU0MGMzYmI5MjUxNmNmOWIyNjE4NTg2Mzk3ZjExOGVmZWFkOTdmNA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NmMzOWM0MDFkMmY5NzA5NGY3ZjlmYmI4N2ExZGQ0Y2Y2YTU1NzJmZDI0ZDhk
|
10
|
+
N2IzZTBlYzU4ZDU5NTQyYzE0NTVjNjY3ZjNiMzE0YzgxMWYwZGUwMWNkYTIz
|
11
|
+
MzVhMDM3MWE0ZmFlYTJjOTBiY2YxNjYyNDBhYzk3MTc5ODkwNzg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTY3YmYwYzdjMTg2ZjllYzk5ZjM1NTQ0ZGU2NzA3ZTQxMjc0MDMxY2YwOGNh
|
14
|
+
OWY3YmRlNmQ3YjFlMmUwZTQ1NDMwYjk0NTg0MTAyMDBkMTE1NGM2OTg3NWE4
|
15
|
+
OTdhM2RjZWYzYTViYWE0NWE5MjVkNWNjNjQxOWFjMDViZmQ2NWQ=
|
data/lib/rack/jsonr/jsonr.rb
CHANGED
@@ -5,7 +5,7 @@ module Rack
|
|
5
5
|
# Based on Rack-JSONP by Flinn Mueller (http://actsasflinn.com/)
|
6
6
|
include Rack::Utils
|
7
7
|
|
8
|
-
|
8
|
+
HTTP_METHODS_TO_OVERRIDE = %w(HEAD PUT POST DELETE OPTIONS PATCH)
|
9
9
|
METHOD_OVERRIDE_PARAM_KEY = '_method'.freeze
|
10
10
|
HTTP_METHOD_OVERRIDE_HEADER = 'HTTP_X_HTTP_METHOD_OVERRIDE'.freeze
|
11
11
|
|
@@ -27,13 +27,7 @@ module Rack
|
|
27
27
|
request = Rack::Request.new(env)
|
28
28
|
params = request.params
|
29
29
|
|
30
|
-
|
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
|
36
|
-
end
|
30
|
+
self.class.intercept_method_override(env, request, params, @options[:method_override])
|
37
31
|
|
38
32
|
if is_jsonp_request?(request)
|
39
33
|
response = format_jsonp(request.params.delete('callback'), status, headers, response)
|
@@ -51,6 +45,20 @@ module Rack
|
|
51
45
|
[status, headers, response]
|
52
46
|
end
|
53
47
|
|
48
|
+
def self.intercept_method_override(env, request, params, override_scope)
|
49
|
+
if is_jsonp_request?(request) or override_scope == :all
|
50
|
+
method_override = (params[METHOD_OVERRIDE_PARAM_KEY] || env[HTTP_METHOD_OVERRIDE_HEADER]).to_s.upcase
|
51
|
+
if HTTP_METHODS_TO_OVERRIDE.include?(method_override)
|
52
|
+
env['rack.jsonr_method_override.original_method'] = env['REQUEST_METHOD']
|
53
|
+
env['REQUEST_METHOD'] = method_override
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.is_jsonp_request?(request)
|
59
|
+
(request.params.include?('callback') and request.get?)
|
60
|
+
end
|
61
|
+
|
54
62
|
private
|
55
63
|
|
56
64
|
def is_json_response?(headers)
|
@@ -61,10 +69,6 @@ module Rack
|
|
61
69
|
@is_jsonp_request ||= self.class.is_jsonp_request?(request)
|
62
70
|
end
|
63
71
|
|
64
|
-
def self.is_jsonp_request?(request)
|
65
|
-
(request.params.include?('callback') and request.get?)
|
66
|
-
end
|
67
|
-
|
68
72
|
# Formats the JSONP padding to include body, headers and http status
|
69
73
|
#
|
70
74
|
def format_jsonp(callback, status, headers, response, x_headers={}, body='')
|
data/lib/rack/jsonr/version.rb
CHANGED