faraday-http-cache 2.0.0 → 2.3.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 +5 -5
- data/LICENSE +0 -2
- data/README.md +14 -6
- data/lib/faraday/http_cache/cache_control.rb +1 -0
- data/lib/faraday/http_cache/request.rb +3 -1
- data/lib/faraday/http_cache/response.rb +3 -2
- data/lib/faraday/http_cache/storage.rb +3 -2
- data/lib/faraday/http_cache.rb +24 -23
- data/spec/binary_spec.rb +2 -1
- data/spec/cache_control_spec.rb +1 -0
- data/spec/http_cache_spec.rb +15 -6
- data/spec/instrumentation_spec.rb +1 -0
- data/spec/json_spec.rb +1 -0
- data/spec/request_spec.rb +1 -0
- data/spec/response_spec.rb +15 -6
- data/spec/spec_helper.rb +8 -3
- data/spec/storage_spec.rb +8 -7
- data/spec/support/test_app.rb +6 -1
- data/spec/support/test_server.rb +8 -6
- data/spec/validation_spec.rb +1 -0
- metadata +23 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 962b23db73b9799330e7229f9a6d6e252705a55f3c3ad316f810132160a30522
|
4
|
+
data.tar.gz: 51a43a544f924e75c00ffffd777368cf995000a3855e1ea7b9b86fb54b5f6b2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57de8b27682d5aa8367fd7612ec3814c300a0856ba7e1ee61354646117a2370f216981b60f5224662236444a44669a70840fb07118602a82b66a0c886ae1540d
|
7
|
+
data.tar.gz: d8e1644ed674c3c7a6c8f44adfe83eda6f9268590235330eaf0ed62ec41795a97a35f28f52bddf7c3103a8cef6c849330167b1b708a6c8124da642e371bf434b
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Faraday Http Cache
|
2
2
|
|
3
|
-
[](https://travis-ci.org/sourcelevel/faraday-http-cache)
|
4
4
|
|
5
5
|
a [Faraday](https://github.com/lostisland/faraday) middleware that respects HTTP cache,
|
6
6
|
by checking expiration and validation of the stored responses.
|
@@ -53,9 +53,16 @@ This type of store **might not be persisted across multiple processes or connect
|
|
53
53
|
so it is probably not suitable for most production environments.
|
54
54
|
Make sure that you configure a store that is suitable for you.
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
The stdlib `JSON` module is used for serialization by default, which can struggle with unicode
|
57
|
+
characters in responses. For example, if your JSON returns `"name": "Raül"` then you might see
|
58
|
+
errors like:
|
59
|
+
|
60
|
+
```
|
61
|
+
Response could not be serialized: "\xC3" from ASCII-8BIT to UTF-8. Try using Marshal to serialize.
|
62
|
+
```
|
63
|
+
|
64
|
+
For full unicode support, or if you expect to be dealing with images, you can use
|
65
|
+
[Marshal][marshal] instead. Alternatively you could use another json library like `oj` or `yajl-ruby`.
|
59
66
|
|
60
67
|
```ruby
|
61
68
|
client = Faraday.new do |builder|
|
@@ -120,7 +127,7 @@ end
|
|
120
127
|
|
121
128
|
## See it live
|
122
129
|
|
123
|
-
You can clone this repository, install
|
130
|
+
You can clone this repository, install its dependencies with Bundler (run `bundle install`) and
|
124
131
|
execute the files under the `examples` directory to see a sample of the middleware usage.
|
125
132
|
|
126
133
|
## What gets cached?
|
@@ -153,6 +160,7 @@ client.get('http://site/api/some-private-resource') # => will be cached
|
|
153
160
|
|
154
161
|
## License
|
155
162
|
|
156
|
-
Copyright (c) 2012-
|
163
|
+
Copyright (c) 2012-2018 Plataformatec.
|
164
|
+
Copyright (c) 2019 SourceLevel and contributors.
|
157
165
|
|
158
166
|
[marshal]: http://www.ruby-doc.org/core-2.0/Marshal.html
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Faraday
|
3
4
|
class HttpCache < Faraday::Middleware
|
4
5
|
# Internal: A class to represent a request
|
@@ -24,6 +25,7 @@ module Faraday
|
|
24
25
|
def cacheable?
|
25
26
|
return false if method != :get && method != :head
|
26
27
|
return false if cache_control.no_store?
|
28
|
+
|
27
29
|
true
|
28
30
|
end
|
29
31
|
|
@@ -39,7 +41,7 @@ module Faraday
|
|
39
41
|
def serializable_hash
|
40
42
|
{
|
41
43
|
method: @method,
|
42
|
-
url: @url,
|
44
|
+
url: @url.to_s,
|
43
45
|
headers: @headers
|
44
46
|
}
|
45
47
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'time'
|
3
4
|
require 'faraday/http_cache/cache_control'
|
4
5
|
|
@@ -50,7 +51,7 @@ module Faraday
|
|
50
51
|
#
|
51
52
|
# Returns true if the response is fresh, otherwise false.
|
52
53
|
def fresh?
|
53
|
-
!cache_control.
|
54
|
+
!cache_control.no_cache? && ttl && ttl > 0
|
54
55
|
end
|
55
56
|
|
56
57
|
# Internal: Checks if the Response returned a 'Not Modified' status.
|
@@ -204,7 +205,7 @@ module Faraday
|
|
204
205
|
# Returns nothing.
|
205
206
|
def ensure_date_header!
|
206
207
|
date
|
207
|
-
rescue
|
208
|
+
rescue StandardError
|
208
209
|
headers['Date'] = @now.httpdate
|
209
210
|
end
|
210
211
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'json'
|
3
4
|
require 'digest/sha1'
|
4
5
|
|
@@ -56,7 +57,7 @@ module Faraday
|
|
56
57
|
entries << entry
|
57
58
|
|
58
59
|
cache.write(key, entries)
|
59
|
-
rescue Encoding::UndefinedConversionError => e
|
60
|
+
rescue ::Encoding::UndefinedConversionError => e
|
60
61
|
warn "Response could not be serialized: #{e.message}. Try using Marshal to serialize."
|
61
62
|
raise e
|
62
63
|
end
|
@@ -167,7 +168,7 @@ module Faraday
|
|
167
168
|
end
|
168
169
|
|
169
170
|
def warn(message)
|
170
|
-
@logger
|
171
|
+
@logger&.warn(message)
|
171
172
|
end
|
172
173
|
end
|
173
174
|
|
data/lib/faraday/http_cache.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'faraday'
|
3
4
|
|
4
5
|
require 'faraday/http_cache/storage'
|
@@ -19,7 +20,7 @@ module Faraday
|
|
19
20
|
#
|
20
21
|
# # Using the middleware with a simple client:
|
21
22
|
# client = Faraday.new do |builder|
|
22
|
-
# builder.
|
23
|
+
# builder.use :http_cache, store: my_store_backend
|
23
24
|
# builder.adapter Faraday.default_adapter
|
24
25
|
# end
|
25
26
|
#
|
@@ -44,7 +45,7 @@ module Faraday
|
|
44
45
|
# builder.use :http_cache, store: Rails.cache, instrumenter: ActiveSupport::Notifications
|
45
46
|
# end
|
46
47
|
class HttpCache < Faraday::Middleware
|
47
|
-
UNSAFE_METHODS = [
|
48
|
+
UNSAFE_METHODS = %i[post put delete patch].freeze
|
48
49
|
|
49
50
|
ERROR_STATUSES = (400..499).freeze
|
50
51
|
|
@@ -61,7 +62,7 @@ module Faraday
|
|
61
62
|
# The response was cached and the server has validated it with a 304 response.
|
62
63
|
:valid,
|
63
64
|
|
64
|
-
# The response was
|
65
|
+
# The response was cached but was not revalidated by the server.
|
65
66
|
:invalid,
|
66
67
|
|
67
68
|
# No response was found in the cache.
|
@@ -70,8 +71,8 @@ module Faraday
|
|
70
71
|
# The response can't be cached.
|
71
72
|
:uncacheable,
|
72
73
|
|
73
|
-
# The request
|
74
|
-
:
|
74
|
+
# The request was cached but need to be revalidated by the server.
|
75
|
+
:must_revalidate
|
75
76
|
].freeze
|
76
77
|
|
77
78
|
# Public: Initializes a new HttpCache middleware.
|
@@ -99,14 +100,21 @@ module Faraday
|
|
99
100
|
# # Initialize the middleware with a MemoryStore and logger
|
100
101
|
# store = ActiveSupport::Cache.lookup_store
|
101
102
|
# Faraday::HttpCache.new(app, store: store, logger: my_logger)
|
102
|
-
def initialize(app,
|
103
|
+
def initialize(app, options = {})
|
103
104
|
super(app)
|
104
105
|
|
105
|
-
|
106
|
-
@
|
107
|
-
@
|
108
|
-
@
|
109
|
-
@
|
106
|
+
options = options.dup
|
107
|
+
@logger = options.delete(:logger)
|
108
|
+
@shared_cache = options.delete(:shared_cache) { true }
|
109
|
+
@instrumenter = options.delete(:instrumenter)
|
110
|
+
@instrument_name = options.delete(:instrument_name) { EVENT_NAME }
|
111
|
+
|
112
|
+
store = options.delete(:store)
|
113
|
+
serializer = options.delete(:serializer)
|
114
|
+
|
115
|
+
raise ArgumentError, "Unknown options: #{options.inspect}" unless options.empty?
|
116
|
+
|
117
|
+
@storage = Storage.new(store: store, serializer: serializer, logger: @logger)
|
110
118
|
end
|
111
119
|
|
112
120
|
# Public: Process the request into a duplicate of this instance to
|
@@ -132,15 +140,7 @@ module Faraday
|
|
132
140
|
response = nil
|
133
141
|
|
134
142
|
if @request.cacheable?
|
135
|
-
response =
|
136
|
-
trace :bypass
|
137
|
-
@app.call(env).on_complete do |fresh_env|
|
138
|
-
response = Response.new(create_response(fresh_env))
|
139
|
-
store(response)
|
140
|
-
end
|
141
|
-
else
|
142
|
-
process(env)
|
143
|
-
end
|
143
|
+
response = process(env)
|
144
144
|
else
|
145
145
|
trace :unacceptable
|
146
146
|
response = @app.call(env)
|
@@ -194,10 +194,11 @@ module Faraday
|
|
194
194
|
|
195
195
|
return fetch(env) if entry.nil?
|
196
196
|
|
197
|
-
if entry.fresh?
|
197
|
+
if entry.fresh? && !@request.no_cache?
|
198
198
|
response = entry.to_response(env)
|
199
199
|
trace :fresh
|
200
200
|
else
|
201
|
+
trace :must_revalidate
|
201
202
|
response = validate(entry, env)
|
202
203
|
end
|
203
204
|
|
@@ -270,7 +271,7 @@ module Faraday
|
|
270
271
|
end
|
271
272
|
|
272
273
|
def delete(request, response)
|
273
|
-
headers = %w
|
274
|
+
headers = %w[Location Content-Location]
|
274
275
|
headers.each do |header|
|
275
276
|
url = response.headers[header]
|
276
277
|
@storage.delete(url) if url
|
@@ -304,7 +305,7 @@ module Faraday
|
|
304
305
|
|
305
306
|
{
|
306
307
|
status: hash[:status],
|
307
|
-
body: hash[:body],
|
308
|
+
body: hash[:body] || hash[:response_body],
|
308
309
|
response_headers: hash[:response_headers]
|
309
310
|
}
|
310
311
|
end
|
data/spec/binary_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
describe Faraday::HttpCache do
|
@@ -10,7 +11,7 @@ describe Faraday::HttpCache do
|
|
10
11
|
stack.adapter adapter.to_sym
|
11
12
|
end
|
12
13
|
end
|
13
|
-
let(:data) { IO.binread File.expand_path('
|
14
|
+
let(:data) { IO.binread File.expand_path('support/empty.png', __dir__) }
|
14
15
|
|
15
16
|
it 'works fine with binary data' do
|
16
17
|
expect(client.get('image').body).to eq data
|
data/spec/cache_control_spec.rb
CHANGED
data/spec/http_cache_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
describe Faraday::HttpCache do
|
@@ -36,7 +37,7 @@ describe Faraday::HttpCache do
|
|
36
37
|
|
37
38
|
it 'adds a trace of the actions performed to the env' do
|
38
39
|
response = client.post('post')
|
39
|
-
expect(response.env[:http_cache_trace]).to eq([
|
40
|
+
expect(response.env[:http_cache_trace]).to eq(%i[unacceptable delete])
|
40
41
|
end
|
41
42
|
|
42
43
|
describe 'cache invalidation' do
|
@@ -180,9 +181,12 @@ describe Faraday::HttpCache do
|
|
180
181
|
end
|
181
182
|
|
182
183
|
context 'when the request has a "no-cache" directive' do
|
183
|
-
it '
|
184
|
-
client.get('
|
185
|
-
expect(client.get('
|
184
|
+
it 'revalidates the cache' do
|
185
|
+
expect(client.get('etag').body).to eq('1')
|
186
|
+
expect(client.get('etag', nil, 'Cache-Control' => 'no-cache').body).to eq('1')
|
187
|
+
|
188
|
+
expect(client.get('get', nil).body).to eq('2')
|
189
|
+
expect(client.get('etag', nil, 'Cache-Control' => 'no-cache').body).to eq('3')
|
186
190
|
end
|
187
191
|
|
188
192
|
it 'caches the response' do
|
@@ -224,7 +228,7 @@ describe Faraday::HttpCache do
|
|
224
228
|
|
225
229
|
it 'logs that the request with "Last-Modified" was revalidated' do
|
226
230
|
client.get('timestamped')
|
227
|
-
expect(logger).to receive(:debug) { |&block| expect(block.call).to eq('HTTP Cache: [GET /timestamped] valid, store') }
|
231
|
+
expect(logger).to receive(:debug) { |&block| expect(block.call).to eq('HTTP Cache: [GET /timestamped] must_revalidate, valid, store') }
|
228
232
|
expect(client.get('timestamped').body).to eq('1')
|
229
233
|
end
|
230
234
|
|
@@ -235,7 +239,7 @@ describe Faraday::HttpCache do
|
|
235
239
|
|
236
240
|
it 'logs that the request with "ETag" was revalidated' do
|
237
241
|
client.get('etag')
|
238
|
-
expect(logger).to receive(:debug) { |&block| expect(block.call).to eq('HTTP Cache: [GET /etag] valid, store') }
|
242
|
+
expect(logger).to receive(:debug) { |&block| expect(block.call).to eq('HTTP Cache: [GET /etag] must_revalidate, valid, store') }
|
239
243
|
expect(client.get('etag').body).to eq('1')
|
240
244
|
end
|
241
245
|
|
@@ -274,6 +278,11 @@ describe Faraday::HttpCache do
|
|
274
278
|
expect(first_vary).not_to eql(second_vary)
|
275
279
|
end
|
276
280
|
|
281
|
+
it 'caches non-stale response with "must-revalidate" directive' do
|
282
|
+
client.get('must-revalidate')
|
283
|
+
expect(client.get('must-revalidate').body).to eq('1')
|
284
|
+
end
|
285
|
+
|
277
286
|
it 'raises an error when misconfigured' do
|
278
287
|
expect {
|
279
288
|
client = Faraday.new(url: ENV['FARADAY_SERVER']) do |stack|
|
data/spec/json_spec.rb
CHANGED
data/spec/request_spec.rb
CHANGED
data/spec/response_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
describe Faraday::HttpCache::Response do
|
@@ -89,8 +90,16 @@ describe Faraday::HttpCache::Response do
|
|
89
90
|
expect(response).not_to be_fresh
|
90
91
|
end
|
91
92
|
|
92
|
-
it 'is
|
93
|
+
it 'is fresh if the response contains "must-revalidate" and is not stale' do
|
93
94
|
date = (Time.now - 200).httpdate
|
95
|
+
headers = { 'Cache-Control' => 'public, max-age=23880, must-revalidate, no-transform', 'Date' => date }
|
96
|
+
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
97
|
+
|
98
|
+
expect(response).to be_fresh
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'is not fresh if Cache Control has "must-revalidate" and is stale' do
|
102
|
+
date = (Time.now - 500).httpdate
|
94
103
|
headers = { 'Cache-Control' => 'max-age=400, must-revalidate', 'Date' => date }
|
95
104
|
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
96
105
|
|
@@ -220,11 +229,11 @@ describe Faraday::HttpCache::Response do
|
|
220
229
|
describe 'remove age before caching and normalize max-age if non-zero age present' do
|
221
230
|
it 'is fresh if the response still has some time to live' do
|
222
231
|
headers = {
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
232
|
+
'Age' => 6,
|
233
|
+
'Cache-Control' => 'public, max-age=40',
|
234
|
+
'Date' => (Time.now - 38).httpdate,
|
235
|
+
'Expires' => (Time.now - 37).httpdate,
|
236
|
+
'Last-Modified' => (Time.now - 300).httpdate
|
228
237
|
}
|
229
238
|
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
230
239
|
expect(response).to be_fresh
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'uri'
|
3
4
|
require 'socket'
|
4
5
|
|
5
6
|
require 'faraday-http-cache'
|
6
|
-
require 'faraday_middleware'
|
7
7
|
|
8
|
-
|
9
|
-
require '
|
8
|
+
if Gem::Version.new(Faraday::VERSION) < Gem::Version.new('1.0')
|
9
|
+
require 'faraday_middleware'
|
10
|
+
elsif ENV['FARADAY_ADAPTER'] == 'em_http'
|
11
|
+
require 'faraday/em_http'
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'active_support'
|
10
15
|
require 'active_support/cache'
|
11
16
|
|
12
17
|
require 'support/test_app'
|
data/spec/storage_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
describe Faraday::HttpCache::Storage do
|
@@ -43,7 +44,7 @@ describe Faraday::HttpCache::Storage do
|
|
43
44
|
let(:serializer) { JSON }
|
44
45
|
it_behaves_like 'A storage with serialization'
|
45
46
|
|
46
|
-
context 'when ASCII characters in response cannot be converted to UTF-8' do
|
47
|
+
context 'when ASCII characters in response cannot be converted to UTF-8', if: Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.1') do
|
47
48
|
let(:response) do
|
48
49
|
body = String.new("\u2665").force_encoding('ASCII-8BIT')
|
49
50
|
double(:response, serializable_hash: { 'body' => body })
|
@@ -55,7 +56,7 @@ describe Faraday::HttpCache::Storage do
|
|
55
56
|
|
56
57
|
expect {
|
57
58
|
storage.write(request, response)
|
58
|
-
}.to raise_error(Encoding::UndefinedConversionError)
|
59
|
+
}.to raise_error(::Encoding::UndefinedConversionError)
|
59
60
|
expect(logger).to have_received(:warn).with(
|
60
61
|
'Response could not be serialized: "\xE2" from ASCII-8BIT to UTF-8. Try using Marshal to serialize.'
|
61
62
|
)
|
@@ -111,11 +112,11 @@ describe Faraday::HttpCache::Storage do
|
|
111
112
|
describe 'remove age before caching and normalize max-age if non-zero age present' do
|
112
113
|
it 'is fresh if the response still has some time to live' do
|
113
114
|
headers = {
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
115
|
+
'Age' => 6,
|
116
|
+
'Cache-Control' => 'public, max-age=40',
|
117
|
+
'Date' => (Time.now - 38).httpdate,
|
118
|
+
'Expires' => (Time.now - 37).httpdate,
|
119
|
+
'Last-Modified' => (Time.now - 300).httpdate
|
119
120
|
}
|
120
121
|
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
121
122
|
expect(response).to be_fresh
|
data/spec/support/test_app.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'sinatra/base'
|
3
4
|
require 'json'
|
4
5
|
|
@@ -27,7 +28,7 @@ class TestApp < Sinatra::Base
|
|
27
28
|
end
|
28
29
|
|
29
30
|
get '/image' do
|
30
|
-
image = File.expand_path('
|
31
|
+
image = File.expand_path('empty.png', __dir__)
|
31
32
|
data = IO.binread(image)
|
32
33
|
[200, { 'Cache-Control' => 'max-age=400', 'Content-Type' => 'image/png' }, data]
|
33
34
|
end
|
@@ -88,6 +89,10 @@ class TestApp < Sinatra::Base
|
|
88
89
|
[200, { 'Date' => settings.yesterday, 'Expires' => settings.yesterday }, increment_counter]
|
89
90
|
end
|
90
91
|
|
92
|
+
get '/must-revalidate' do
|
93
|
+
[200, { 'Date' => Time.now.httpdate, 'Cache-Control' => 'public, max-age=23880, must-revalidate, no-transform' }, increment_counter]
|
94
|
+
end
|
95
|
+
|
91
96
|
get '/timestamped' do
|
92
97
|
settings.counter += 1
|
93
98
|
header = settings.counter > 2 ? '1' : '2'
|
data/spec/support/test_server.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'net/http'
|
3
4
|
|
4
5
|
class TestServer
|
@@ -27,11 +28,11 @@ class TestServer
|
|
27
28
|
log = File.open('log/test.log', 'w+')
|
28
29
|
log.sync = true
|
29
30
|
webrick_opts = {
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
Port: @port,
|
32
|
+
Logger: WEBrick::Log.new(log),
|
33
|
+
AccessLog: [[log, '[%{X-Faraday-Adapter}i] %m %U -> %s %b']]
|
33
34
|
}
|
34
|
-
Rack::Handler::WEBrick.run(TestApp, webrick_opts)
|
35
|
+
Rack::Handler::WEBrick.run(TestApp, **webrick_opts)
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
@@ -39,7 +40,7 @@ class TestServer
|
|
39
40
|
conn = Net::HTTP.new @host, @port
|
40
41
|
conn.open_timeout = conn.read_timeout = 0.1
|
41
42
|
|
42
|
-
responsive = ->(path) {
|
43
|
+
responsive = ->(path) {
|
43
44
|
begin
|
44
45
|
res = conn.start { conn.get(path) }
|
45
46
|
res.is_a?(Net::HTTPSuccess)
|
@@ -51,6 +52,7 @@ class TestServer
|
|
51
52
|
server_pings = 0
|
52
53
|
loop do
|
53
54
|
break if responsive.call('/ping')
|
55
|
+
|
54
56
|
server_pings += 1
|
55
57
|
sleep 0.05
|
56
58
|
abort 'test server did not managed to start' if server_pings >= 50
|
@@ -61,6 +63,6 @@ class TestServer
|
|
61
63
|
server = TCPServer.new(@host, 0)
|
62
64
|
server.addr[1]
|
63
65
|
ensure
|
64
|
-
server
|
66
|
+
server&.close
|
65
67
|
end
|
66
68
|
end
|
data/spec/validation_spec.rb
CHANGED
metadata
CHANGED
@@ -1,32 +1,33 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-http-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
|
7
|
+
- George Guimarães
|
8
|
+
- Gustavo Araujo
|
9
|
+
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2022-05-25 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: faraday
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
|
-
- - "
|
18
|
+
- - ">="
|
18
19
|
- !ruby/object:Gem::Version
|
19
20
|
version: '0.8'
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
|
-
- - "
|
25
|
+
- - ">="
|
25
26
|
- !ruby/object:Gem::Version
|
26
27
|
version: '0.8'
|
27
28
|
description: Middleware to handle HTTP caching
|
28
29
|
email:
|
29
|
-
- opensource@
|
30
|
+
- opensource@sourcelevel.io
|
30
31
|
executables: []
|
31
32
|
extensions: []
|
32
33
|
extra_rdoc_files: []
|
@@ -52,11 +53,11 @@ files:
|
|
52
53
|
- spec/support/test_app.rb
|
53
54
|
- spec/support/test_server.rb
|
54
55
|
- spec/validation_spec.rb
|
55
|
-
homepage: https://github.com/
|
56
|
+
homepage: https://github.com/sourcelevel/faraday-http-cache
|
56
57
|
licenses:
|
57
|
-
- Apache
|
58
|
+
- Apache-2.0
|
58
59
|
metadata: {}
|
59
|
-
post_install_message:
|
60
|
+
post_install_message:
|
60
61
|
rdoc_options: []
|
61
62
|
require_paths:
|
62
63
|
- lib
|
@@ -64,29 +65,28 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
65
|
requirements:
|
65
66
|
- - ">="
|
66
67
|
- !ruby/object:Gem::Version
|
67
|
-
version: 2.
|
68
|
+
version: 2.4.0
|
68
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
70
|
requirements:
|
70
71
|
- - ">="
|
71
72
|
- !ruby/object:Gem::Version
|
72
73
|
version: '0'
|
73
74
|
requirements: []
|
74
|
-
|
75
|
-
|
76
|
-
signing_key:
|
75
|
+
rubygems_version: 3.0.3
|
76
|
+
signing_key:
|
77
77
|
specification_version: 4
|
78
78
|
summary: A Faraday middleware that stores and validates cache expiration.
|
79
79
|
test_files:
|
80
|
-
- spec/binary_spec.rb
|
81
|
-
- spec/cache_control_spec.rb
|
82
|
-
- spec/http_cache_spec.rb
|
83
|
-
- spec/instrumentation_spec.rb
|
84
|
-
- spec/json_spec.rb
|
85
|
-
- spec/request_spec.rb
|
86
|
-
- spec/response_spec.rb
|
87
80
|
- spec/spec_helper.rb
|
81
|
+
- spec/validation_spec.rb
|
82
|
+
- spec/json_spec.rb
|
83
|
+
- spec/instrumentation_spec.rb
|
88
84
|
- spec/storage_spec.rb
|
89
|
-
- spec/
|
85
|
+
- spec/http_cache_spec.rb
|
86
|
+
- spec/binary_spec.rb
|
90
87
|
- spec/support/test_app.rb
|
88
|
+
- spec/support/empty.png
|
91
89
|
- spec/support/test_server.rb
|
92
|
-
- spec/
|
90
|
+
- spec/request_spec.rb
|
91
|
+
- spec/cache_control_spec.rb
|
92
|
+
- spec/response_spec.rb
|