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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzFjZjg3ZjY1MjkxODRmZjdlMDhmMzRjMDg5OGIzZTM0ZWI4ODI1YQ==
4
+ MzBlYjQzNDI1OWI4Njk0NDE4NWQ2NzUwNTAxZTBhZTE5MWNhMGJiZg==
5
5
  data.tar.gz: !binary |-
6
- ZDkzZGNmOWJlMWExMmUwNzRmMWUyZjMxYjRhMDc1NjIyNzg3NTc4Nw==
6
+ Y2YxMTA2OTc2NjM0MjBkMzhhOGQ0MTQyNGY2YjliYTM3YmE4MjE4NA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZDBjZWFhZGQxMmI1OTk2ODVkOWQ4Y2MwMmJhZWYxODRmNTQxZWI0MWQzM2My
10
- YTM4Njc0ZDFhZjQwNDk3OGJlNDE4NDViZDZmNzA1MDQ0YTgyMmQ5MDkwMjU5
11
- ODU4Yjk3YzgwMTE1NWMwZWRlMjY4ZjM3NjlkMDQ4ZTNkYzU1N2Q=
9
+ MjljNjk5MmE2YjlhODhjOTI1ZDJiZTVkMzYzYWZmNWM4MzE0NjFiYjA4Zjhk
10
+ MWJlOTgzNDI1MzkyZmZiMzMyNmY0YWJlMzhhYjZhNDlhMWM0YmUxM2M2OWY4
11
+ YzI2OTA5Zjc5MTZlY2Y3YTdiYzYzZGRiNWM4MTc2M2EzOTgzNTY=
12
12
  data.tar.gz: !binary |-
13
- OTAyMGQxYmNhY2I0MTM5MDlmNWQzNTIwZjRlMDU2NDEyNzAxYmRjNmNkMjRh
14
- ZDMyZmQ4MTUzYTY5MWYyN2E1MGRiMGVlNWFiODczN2U0ZWQ1NzE3Y2JlOWJh
15
- MDQ5MGQ2YjRiMDk3YTNlNTk5MTE3NjM0YzAyODEwZTM5ZGYzYjg=
13
+ ZTBkMGM1M2ExN2JlMmZmZDRmNWU0MTRiYjNjYTU0YzQ2MjI3YjQ4MTY5Mzcz
14
+ YjgzNTM1ZTk4MzFhN2I2ZGM0NDBhNGMzZWQ2MWVjOGNhZWNiYjU2Y2MzNjQw
15
+ MThiYTVmYjk3ZDcwOGYxZmVkYmYxOGNiM2YwNmRmYWE0MDhmYzg=
@@ -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
- def initialize(app)
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
- env['REQUEST_METHOD'] = params['request_method'].upcase if params['request_method'] and ['POST','PUT','DELETE'].include?(params['request_method'].upcase)
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) #and is_json_response?(headers)
38
+ if is_jsonp_request?(request)
34
39
  response = format_jsonp(request.params.delete('callback'), status, headers, response)
35
40
  status = 200
36
41
 
@@ -1,3 +1,3 @@
1
1
  class Rack::JSONR
2
- VERSION = '0.1.4'
2
+ VERSION = '0.2.0'
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.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caleb Clark