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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzBlYjQzNDI1OWI4Njk0NDE4NWQ2NzUwNTAxZTBhZTE5MWNhMGJiZg==
4
+ NDJiYzFiMzQ2NTQ3OWUxZjYzOTEzN2ZjNTY2YjI2MWI4YzFiNmJjOA==
5
5
  data.tar.gz: !binary |-
6
- Y2YxMTA2OTc2NjM0MjBkMzhhOGQ0MTQyNGY2YjliYTM3YmE4MjE4NA==
6
+ NjU0MGMzYmI5MjUxNmNmOWIyNjE4NTg2Mzk3ZjExOGVmZWFkOTdmNA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MjljNjk5MmE2YjlhODhjOTI1ZDJiZTVkMzYzYWZmNWM4MzE0NjFiYjA4Zjhk
10
- MWJlOTgzNDI1MzkyZmZiMzMyNmY0YWJlMzhhYjZhNDlhMWM0YmUxM2M2OWY4
11
- YzI2OTA5Zjc5MTZlY2Y3YTdiYzYzZGRiNWM4MTc2M2EzOTgzNTY=
9
+ NmMzOWM0MDFkMmY5NzA5NGY3ZjlmYmI4N2ExZGQ0Y2Y2YTU1NzJmZDI0ZDhk
10
+ N2IzZTBlYzU4ZDU5NTQyYzE0NTVjNjY3ZjNiMzE0YzgxMWYwZGUwMWNkYTIz
11
+ MzVhMDM3MWE0ZmFlYTJjOTBiY2YxNjYyNDBhYzk3MTc5ODkwNzg=
12
12
  data.tar.gz: !binary |-
13
- ZTBkMGM1M2ExN2JlMmZmZDRmNWU0MTRiYjNjYTU0YzQ2MjI3YjQ4MTY5Mzcz
14
- YjgzNTM1ZTk4MzFhN2I2ZGM0NDBhNGMzZWQ2MWVjOGNhZWNiYjU2Y2MzNjQw
15
- MThiYTVmYjk3ZDcwOGYxZmVkYmYxOGNiM2YwNmRmYWE0MDhmYzg=
13
+ NTY3YmYwYzdjMTg2ZjllYzk5ZjM1NTQ0ZGU2NzA3ZTQxMjc0MDMxY2YwOGNh
14
+ OWY3YmRlNmQ3YjFlMmUwZTQ1NDMwYjk0NTg0MTAyMDBkMTE1NGM2OTg3NWE4
15
+ OTdhM2RjZWYzYTViYWE0NWE5MjVkNWNjNjQxOWFjMDViZmQ2NWQ=
@@ -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
- HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS PATCH)
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
- 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
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='')
@@ -1,3 +1,3 @@
1
1
  class Rack::JSONR
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-jsonr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caleb Clark