faraday-http-cache 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/faraday/http_cache/response.rb +1 -1
- data/spec/http_cache_spec.rb +8 -0
- data/spec/response_spec.rb +9 -1
- data/spec/support/test_app.rb +4 -0
- 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: 591c5305967c1a77f52be280ad1c2b31f8b6c1d5
|
4
|
+
data.tar.gz: b7a40463bdffe22b23ad0a602b225f1df3041bd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20567be380e251d4c16d9b3ba1a3f15feca47c1d3f2130f2f262c0e42c07180bd92179c71ae812dbedf44c779af4ade72c7a1fdaaccab706b876e917d4e477b5
|
7
|
+
data.tar.gz: 1d2c5ab40e991aa6acd2862d40f2fb44ca0741c4f0c708f7751805340bc941cbeda505d07be1d021b8375381fc952e9fbcbe4f507ad9719cfa311d5b7337139e
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Faraday Http Cache
|
2
2
|
|
3
|
-
[![Build Status](https://secure.travis-ci.org/plataformatec/faraday-http-cache.
|
3
|
+
[![Build Status](https://secure.travis-ci.org/plataformatec/faraday-http-cache.svg?branch=master)](https://travis-ci.org/plataformatec/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.
|
@@ -30,7 +30,7 @@ end
|
|
30
30
|
```
|
31
31
|
|
32
32
|
The middleware accepts a `store` option for the cache backend responsible for recording
|
33
|
-
the API responses that should be stored. Stores should respond to `write` and `
|
33
|
+
the API responses that should be stored. Stores should respond to `write`, `read` and `delete`,
|
34
34
|
just like an object from the `ActiveSupport::Cache` API.
|
35
35
|
|
36
36
|
```ruby
|
data/spec/http_cache_spec.rb
CHANGED
@@ -190,6 +190,14 @@ describe Faraday::HttpCache do
|
|
190
190
|
end
|
191
191
|
end
|
192
192
|
|
193
|
+
context 'when the response has a "no-cache" directive' do
|
194
|
+
it 'always revalidate the cached response' do
|
195
|
+
client.get('no_cache')
|
196
|
+
expect(client.get('no_cache').body).to eq('2')
|
197
|
+
expect(client.get('no_cache').body).to eq('3')
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
193
201
|
it 'logs that a GET response is stored' do
|
194
202
|
expect(logger).to receive(:debug) { |&block| expect(block.call).to eq('HTTP Cache: [GET /get] miss, store') }
|
195
203
|
client.get('get')
|
data/spec/response_spec.rb
CHANGED
@@ -72,13 +72,21 @@ describe Faraday::HttpCache::Response do
|
|
72
72
|
expect(response).to be_fresh
|
73
73
|
end
|
74
74
|
|
75
|
-
it 'is not fresh
|
75
|
+
it 'is not fresh if the ttl has expired' do
|
76
76
|
date = (Time.now - 500).httpdate
|
77
77
|
headers = { 'Cache-Control' => 'max-age=400', 'Date' => date }
|
78
78
|
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
79
79
|
|
80
80
|
expect(response).not_to be_fresh
|
81
81
|
end
|
82
|
+
|
83
|
+
it 'is not fresh if Cache Control has "no-cache"' do
|
84
|
+
date = (Time.now - 200).httpdate
|
85
|
+
headers = { 'Cache-Control' => 'max-age=400, no-cache', 'Date' => date }
|
86
|
+
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
87
|
+
|
88
|
+
expect(response).not_to be_fresh
|
89
|
+
end
|
82
90
|
end
|
83
91
|
|
84
92
|
it 'sets the "Date" header if is not present' do
|
data/spec/support/test_app.rb
CHANGED
@@ -109,6 +109,10 @@ class TestApp < Sinatra::Base
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
+
get '/no_cache' do
|
113
|
+
[200, { 'Cache-Control' => 'max-age=200, no-cache', 'ETag' => settings.counter.to_s }, increment_counter]
|
114
|
+
end
|
115
|
+
|
112
116
|
get '/vary' do
|
113
117
|
[200, { 'Cache-Control' => 'max-age=50', 'Vary' => 'User-Agent' }, increment_counter]
|
114
118
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-http-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Mazza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
72
|
version: '0'
|
73
73
|
requirements: []
|
74
74
|
rubyforge_project:
|
75
|
-
rubygems_version: 2.
|
75
|
+
rubygems_version: 2.5.1
|
76
76
|
signing_key:
|
77
77
|
specification_version: 4
|
78
78
|
summary: A Faraday middleware that stores and validates cache expiration.
|