faraday_middleware 0.13.1 → 0.14.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7beabdfd775a267ce0c8be26be6d42177d2b586e39ac1f4e8e2e07d9554ea53
|
4
|
+
data.tar.gz: c06131c5aaaea0affda0f77c3459da0ce3f2404c437893fb088a41ebbc502313
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bca7b8a07b9113d6e1df94e2b5ec426496bc914f04d76bc4c755dcaf4d57d33cf0f85c68db94103acc197860428191bc838b79ef8187f682749eba2523add633
|
7
|
+
data.tar.gz: 35dc075c2606f365407947c3f24be9c6e1d9b59948198d532ab3254c6ae3b1fd975de519a9e80b054cb807c204c5b23be13ba17ca59014b05063facc07bd4c5c
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
Faraday Middleware
|
2
2
|
==================
|
3
|
+
[](https://rubygems.org/gems/faraday_middleware)
|
4
|
+
[](https://travis-ci.org/lostisland/faraday_middleware)
|
5
|
+
[](https://codeclimate.com/github/lostisland/faraday_middleware/maintainability)
|
3
6
|
|
4
7
|
A collection of useful [Faraday][] middleware. [See the documentation][docs].
|
5
8
|
|
@@ -37,13 +37,17 @@ module FaradayMiddleware
|
|
37
37
|
def call(env)
|
38
38
|
env[:request_headers][ACCEPT_ENCODING] ||= SUPPORTED_ENCODINGS
|
39
39
|
@app.call(env).on_complete do |response_env|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
40
|
+
if response_env[:body].empty?
|
41
|
+
reset_body(response_env, &method(:raw_body))
|
42
|
+
else
|
43
|
+
case response_env[:response_headers][CONTENT_ENCODING]
|
44
|
+
when 'gzip'
|
45
|
+
reset_body(response_env, &method(:uncompress_gzip))
|
46
|
+
when 'deflate'
|
47
|
+
reset_body(response_env, &method(:inflate))
|
48
|
+
when 'br'
|
49
|
+
reset_body(response_env, &method(:brotli_inflate))
|
50
|
+
end
|
47
51
|
end
|
48
52
|
end
|
49
53
|
end
|
@@ -81,5 +85,9 @@ module FaradayMiddleware
|
|
81
85
|
def brotli_inflate(body)
|
82
86
|
Brotli.inflate(body)
|
83
87
|
end
|
88
|
+
|
89
|
+
def raw_body(body)
|
90
|
+
body
|
91
|
+
end
|
84
92
|
end
|
85
93
|
end
|
@@ -29,6 +29,7 @@ module FaradayMiddleware
|
|
29
29
|
# :write_options - Hash of settings that should be passed as the third
|
30
30
|
# options parameter to the cache's #write method. If not
|
31
31
|
# specified, no options parameter will be passed.
|
32
|
+
# :full_key - Boolean - use full URL (url.host + url.request_uri) as cache key
|
32
33
|
#
|
33
34
|
# Yields if no cache is given. The block should return a cache object.
|
34
35
|
def initialize(app, cache = nil, options = {})
|
@@ -65,14 +66,17 @@ module FaradayMiddleware
|
|
65
66
|
url.query = params.any? ? build_query(params) : nil
|
66
67
|
end
|
67
68
|
url.normalize!
|
68
|
-
|
69
|
-
Digest::SHA1.hexdigest(url.request_uri)
|
69
|
+
Digest::SHA1.hexdigest(full_key? ? url.host + url.request_uri : url.request_uri)
|
70
70
|
end
|
71
71
|
|
72
72
|
def params_to_ignore
|
73
73
|
@params_to_ignore ||= Array(@options[:ignore_params]).map { |p| p.to_s }
|
74
74
|
end
|
75
75
|
|
76
|
+
def full_key?
|
77
|
+
@full_key ||= @options[:full_key]
|
78
|
+
end
|
79
|
+
|
76
80
|
def cache_on_complete(env)
|
77
81
|
key = cache_key(env)
|
78
82
|
if cached_response = cache.read(key)
|
@@ -10,8 +10,8 @@ module FaradayMiddleware
|
|
10
10
|
end
|
11
11
|
|
12
12
|
# Store a Proc that receives the body and returns the parsed result.
|
13
|
-
def self.define_parser(parser = nil)
|
14
|
-
@parser = parser ||
|
13
|
+
def self.define_parser(parser = nil, &block)
|
14
|
+
@parser = parser || block || raise(ArgumentError, 'Define parser with a block')
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.inherited(subclass)
|
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.14.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:
|
12
|
+
date: 2020-01-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
requirements: []
|
84
|
-
rubygems_version: 3.0.
|
84
|
+
rubygems_version: 3.0.3
|
85
85
|
signing_key:
|
86
86
|
specification_version: 4
|
87
87
|
summary: Various middleware for Faraday
|