faraday-http-cache 1.3.0 → 1.3.1
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/lib/faraday-http-cache.rb +1 -1
- data/lib/faraday/http_cache.rb +5 -5
- data/lib/faraday/http_cache/cache_control.rb +1 -1
- data/lib/faraday/http_cache/response.rb +11 -2
- data/spec/response_spec.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 942379737f4eb3fb24ad2aee9663f11f0a9a0e6a
|
4
|
+
data.tar.gz: 26bea5cb199a05a64c86bc10db16439fd44351fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e83a8ad2f7020b72a74e7932d343228648e50e68cc0c08ab18002de0fafcfff78598c34c4146ae2b2fd5fa1a1764897767f16b845bedd529886e5974b7279a61
|
7
|
+
data.tar.gz: 8d50e77a3a902a432f8bdafb559fc9a8f30f5904826893ea68c0bbf04b352ad4eb3620d5af228f544cb8938dc3863b4ad693a5ffc2f103d86723945e0dc7b01e
|
data/lib/faraday-http-cache.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'faraday/http_cache'
|
1
|
+
require 'faraday/http_cache'
|
data/lib/faraday/http_cache.rb
CHANGED
@@ -44,14 +44,14 @@ module Faraday
|
|
44
44
|
# end
|
45
45
|
class HttpCache < Faraday::Middleware
|
46
46
|
# Internal: valid options for the 'initialize' configuration Hash.
|
47
|
-
VALID_OPTIONS = [:store, :serializer, :logger, :shared_cache, :instrumenter, :instrument_name]
|
47
|
+
VALID_OPTIONS = [:store, :serializer, :logger, :shared_cache, :instrumenter, :instrument_name].freeze
|
48
48
|
|
49
|
-
UNSAFE_METHODS = [:post, :put, :delete, :patch]
|
49
|
+
UNSAFE_METHODS = [:post, :put, :delete, :patch].freeze
|
50
50
|
|
51
|
-
ERROR_STATUSES = 400..499
|
51
|
+
ERROR_STATUSES = (400..499).freeze
|
52
52
|
|
53
53
|
# The name of the instrumentation event.
|
54
|
-
EVENT_NAME = 'http_cache.faraday'
|
54
|
+
EVENT_NAME = 'http_cache.faraday'.freeze
|
55
55
|
|
56
56
|
CACHE_STATUSES = [
|
57
57
|
# The request was not cacheable.
|
@@ -74,7 +74,7 @@ module Faraday
|
|
74
74
|
|
75
75
|
# The request decided to ignore the cache.
|
76
76
|
:bypass
|
77
|
-
]
|
77
|
+
].freeze
|
78
78
|
|
79
79
|
# Public: Initializes a new HttpCache middleware.
|
80
80
|
#
|
@@ -54,7 +54,7 @@ module Faraday
|
|
54
54
|
def shared_max_age
|
55
55
|
@directives['s-maxage'].to_i if @directives.key?('s-maxage')
|
56
56
|
end
|
57
|
-
|
57
|
+
alias s_maxage shared_max_age
|
58
58
|
|
59
59
|
# Internal: Checks if the 'must-revalidate' directive is present.
|
60
60
|
def must_revalidate?
|
@@ -16,7 +16,7 @@ module Faraday
|
|
16
16
|
# * 302 - 'Found'
|
17
17
|
# * 404 - 'Not Found'
|
18
18
|
# * 410 - 'Gone'
|
19
|
-
CACHEABLE_STATUS_CODES = [200, 203, 300, 301, 302, 307, 404, 410]
|
19
|
+
CACHEABLE_STATUS_CODES = [200, 203, 300, 301, 302, 307, 404, 410].freeze
|
20
20
|
|
21
21
|
# Internal: Gets the actual response Hash (status, headers and body).
|
22
22
|
attr_reader :payload
|
@@ -38,7 +38,7 @@ module Faraday
|
|
38
38
|
@now = Time.now
|
39
39
|
@payload = payload
|
40
40
|
wrap_headers!
|
41
|
-
|
41
|
+
ensure_date_header!
|
42
42
|
|
43
43
|
@last_modified = headers['Last-Modified']
|
44
44
|
@etag = headers['ETag']
|
@@ -198,6 +198,15 @@ module Faraday
|
|
198
198
|
@payload[:response_headers].update(headers) if headers
|
199
199
|
end
|
200
200
|
|
201
|
+
# Internal: Try to parse the Date header, if it fails set it to @now.
|
202
|
+
#
|
203
|
+
# Returns nothing.
|
204
|
+
def ensure_date_header!
|
205
|
+
date
|
206
|
+
rescue
|
207
|
+
headers['Date'] = @now.httpdate
|
208
|
+
end
|
209
|
+
|
201
210
|
# Internal: Gets the headers 'Hash' from the payload.
|
202
211
|
def headers
|
203
212
|
@payload[:response_headers]
|
data/spec/response_spec.rb
CHANGED
@@ -96,6 +96,14 @@ describe Faraday::HttpCache::Response do
|
|
96
96
|
expect(response.date).to be
|
97
97
|
end
|
98
98
|
|
99
|
+
it 'sets the "Date" header if is not a valid RFC 2616 compliant string' do
|
100
|
+
date = Time.now.httpdate
|
101
|
+
headers = { 'Date' => "#{date}, #{date}" }
|
102
|
+
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
103
|
+
|
104
|
+
expect(response.date).to be
|
105
|
+
end
|
106
|
+
|
99
107
|
it 'the response is not modified if the status code is 304' do
|
100
108
|
response = Faraday::HttpCache::Response.new(status: 304)
|
101
109
|
expect(response).to be_not_modified
|
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.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Mazza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|