faraday_middleware 0.11.0.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/faraday_middleware/response/caching.rb +15 -7
- data/lib/faraday_middleware/response/follow_redirects.rb +1 -1
- data/lib/faraday_middleware/response/parse_json.rb +2 -2
- data/lib/faraday_middleware/response/parse_yaml.rb +14 -10
- data/lib/faraday_middleware/response/rashify.rb +1 -1
- data/lib/faraday_middleware/response_middleware.rb +6 -1
- data/lib/faraday_middleware/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c352d19f8d4edebdb7729a98d7c3b1fee0efff81
|
4
|
+
data.tar.gz: 2d9cdcbd18177a69b876046438263c4d212919e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
@@ -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
|
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:
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
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.
|
18
|
+
# YAML.load body
|
15
19
|
# end
|
16
20
|
# end
|
17
21
|
#
|
18
22
|
# Faraday.new(..) do |config|
|
19
|
-
# config.use
|
23
|
+
# config.use UnsafelyParseYaml
|
20
24
|
# ...
|
21
25
|
# end
|
22
26
|
class ParseYaml < ResponseMiddleware
|
23
|
-
dependency '
|
27
|
+
dependency 'safe_yaml/load'
|
24
28
|
|
25
29
|
define_parser do |body|
|
26
|
-
|
30
|
+
SafeYAML.load body
|
27
31
|
end
|
28
32
|
end
|
29
33
|
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
|
-
|
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
|
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.
|
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-
|
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.
|
86
|
+
rubygems_version: 2.6.11
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: Various middleware for Faraday
|