faraday_middleware 0.11.0.1 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 923f7b7b81b0df3d1bcabaf65cab02f10a65ca7e
4
- data.tar.gz: bd043e78e2f16facabd62d2e7003baef37600217
3
+ metadata.gz: c352d19f8d4edebdb7729a98d7c3b1fee0efff81
4
+ data.tar.gz: 2d9cdcbd18177a69b876046438263c4d212919e7
5
5
  SHA512:
6
- metadata.gz: f6c3d53ae343b3d54cf981faf855d89d6aa7b204f37db9b34d66f1e00d0cf656f7919ec003d4ea096da1cfa0a8e1c8f3646ff0a8135f64e7ff24fa9803e40517
7
- data.tar.gz: 413366d67bf0d97e4e2a1645ca6e02a8c4eb9453049bdb27c4f8d8a951697e612571098b53963dc78c841e25d9acfc69f887f2ae10b25ed8cd56fab3f017e24c
6
+ metadata.gz: 3f40ec0ae3ef9fdbd6f3b365c5cff9d936e11dfd720e9a3f363f8dddd93f22e60f4916ae4afba72ccdfc0e0eeb462db5910390cca48e9e7e86550f4165ef2f84
7
+ data.tar.gz: e539f6866668031b76c7dfc9a8b6dca7f641ebdf86f518e2673b0bfe7f31facebaafa4c09aefa1109368a6416a2908b710845b9b519304b8ff1dfd80e8815434
data/README.md CHANGED
@@ -15,7 +15,7 @@ Some dependent libraries are needed only when using specific middleware:
15
15
  * FaradayMiddleware::ParseXml: "multi_xml"
16
16
  * FaradayMiddleware::OAuth: "simple_oauth"
17
17
  * FaradayMiddleware::Mashify: "hashie"
18
- * FaradayMiddleware::Rashify: "rash"
18
+ * FaradayMiddleware::Rashify: "rash_alt" (Make sure to uninstall original rash gem to avoid conflict)
19
19
  * FaradayMiddleware::Instrumentation: "activesupport"
20
20
 
21
21
  Examples
@@ -27,6 +27,9 @@ module FaradayMiddleware
27
27
  # :ignore_params - String name or Array names of query params
28
28
  # that should be ignored when forming the cache
29
29
  # key (default: []).
30
+ # :write_options - Hash of settings that should be passed as the third
31
+ # options parameter to the cache's #write method. If not
32
+ # specified, no options parameter will be passed.
30
33
  #
31
34
  # Yields if no cache is given. The block should return a cache object.
32
35
  def initialize(app, cache = nil, options = {})
@@ -46,10 +49,7 @@ module FaradayMiddleware
46
49
  key = cache_key(env)
47
50
  unless response = cache.read(key) and response
48
51
  response = @app.call(env)
49
-
50
- if CACHEABLE_STATUS_CODES.include?(response.status)
51
- cache.write(key, response)
52
- end
52
+ store_response_in_cache(key, response)
53
53
  end
54
54
  finalize_response(response, env)
55
55
  end
@@ -80,14 +80,22 @@ module FaradayMiddleware
80
80
  else
81
81
  # response.status is nil at this point, any checks need to be done inside on_complete block
82
82
  @app.call(env).on_complete do |response_env|
83
- if CACHEABLE_STATUS_CODES.include?(response_env.status)
84
- cache.write(key, response_env.response)
85
- end
83
+ store_response_in_cache(key, response_env.response)
86
84
  response_env
87
85
  end
88
86
  end
89
87
  end
90
88
 
89
+ def store_response_in_cache(key, response)
90
+ return unless CACHEABLE_STATUS_CODES.include?(response.status)
91
+
92
+ if @options[:write_options]
93
+ cache.write(key, response, @options[:write_options])
94
+ else
95
+ cache.write(key, response)
96
+ end
97
+ end
98
+
91
99
  def finalize_response(response, env)
92
100
  response = response.dup if response.frozen?
93
101
  env[:response] = response
@@ -89,7 +89,7 @@ module FaradayMiddleware
89
89
  end
90
90
 
91
91
  def update_env(env, request_body, response)
92
- env[:url] += safe_escape(response['location'])
92
+ env[:url] += safe_escape(response['location'] || '')
93
93
 
94
94
  if convert_to_get?(response)
95
95
  env[:method] = :get
@@ -7,8 +7,8 @@ module FaradayMiddleware
7
7
  require 'json' unless defined?(::JSON)
8
8
  end
9
9
 
10
- define_parser do |body|
11
- ::JSON.parse body unless body.strip.empty?
10
+ define_parser do |body, parser_options|
11
+ ::JSON.parse(body, parser_options) unless body.strip.empty?
12
12
  end
13
13
 
14
14
  # Public: Override the content-type of the response with "application/json"
@@ -3,27 +3,31 @@ require 'faraday_middleware/response_middleware'
3
3
  module FaradayMiddleware
4
4
  # Public: Parse response bodies as YAML.
5
5
  #
6
- # Warning: this uses `YAML.load()` by default and as such is not safe against
7
- # code injection or DoS attacks. If you're loading resources from an
8
- # untrusted host or over HTTP, you should subclass this middleware and
9
- # redefine it to use `safe_load()` if you're using a Psych version that
10
- # supports it:
6
+ # Warning: This is not backwards compatible with versions of this middleware prior to
7
+ # faraday_middleware v0.12 - prior to this version, we used YAML.load rather than
8
+ # YAMl.safe_load, which exposes serious remote code execution risks - see
9
+ # https://github.com/ruby/psych/issues/119 for details. If you're sure you can trust
10
+ # YAML you're passing, you can set up an unsafe version of this middleware as follows:
11
+ #
12
+ # class UnsafelyParseYaml < FaradayMiddleware::ResponseMiddleware
13
+ # dependency do
14
+ # require 'yaml'
15
+ # end
11
16
  #
12
- # class SafeYaml < FaradayMiddleware::ParseYaml
13
17
  # define_parser do |body|
14
- # YAML.safe_load(body)
18
+ # YAML.load body
15
19
  # end
16
20
  # end
17
21
  #
18
22
  # Faraday.new(..) do |config|
19
- # config.use SafeYaml
23
+ # config.use UnsafelyParseYaml
20
24
  # ...
21
25
  # end
22
26
  class ParseYaml < ResponseMiddleware
23
- dependency 'yaml'
27
+ dependency 'safe_yaml/load'
24
28
 
25
29
  define_parser do |body|
26
- ::YAML.load body
30
+ SafeYAML.load body
27
31
  end
28
32
  end
29
33
  end
@@ -6,7 +6,7 @@ module FaradayMiddleware
6
6
  class Rashify < Mashify
7
7
  dependency do
8
8
  require 'rash'
9
- self.mash_class = ::Hashie::Rash
9
+ self.mash_class = ::Hashie::Mash::Rash
10
10
  end
11
11
  end
12
12
  end
@@ -23,6 +23,7 @@ module FaradayMiddleware
23
23
  def initialize(app = nil, options = {})
24
24
  super(app)
25
25
  @options = options
26
+ @parser_options = options[:parser_options]
26
27
  @content_types = Array(options[:content_type])
27
28
  end
28
29
 
@@ -47,7 +48,11 @@ module FaradayMiddleware
47
48
  def parse(body)
48
49
  if self.class.parser
49
50
  begin
50
- self.class.parser.call(body)
51
+ if @parser_options
52
+ self.class.parser.call(body, @parser_options)
53
+ else
54
+ self.class.parser.call(body)
55
+ end
51
56
  rescue StandardError, SyntaxError => err
52
57
  raise err if err.is_a? SyntaxError and err.class.name != 'Psych::SyntaxError'
53
58
  raise Faraday::Error::ParsingError, err
@@ -1,3 +1,3 @@
1
1
  module FaradayMiddleware
2
- VERSION = "0.11.0.1" unless defined?(FaradayMiddleware::VERSION)
2
+ VERSION = "0.12.0" unless defined?(FaradayMiddleware::VERSION)
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday_middleware
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0.1
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Michaels-Ober
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-01-23 00:00:00.000000000 Z
12
+ date: 2017-07-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  version: '0'
84
84
  requirements: []
85
85
  rubyforge_project:
86
- rubygems_version: 2.4.5
86
+ rubygems_version: 2.6.11
87
87
  signing_key:
88
88
  specification_version: 4
89
89
  summary: Various middleware for Faraday