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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 591c5305967c1a77f52be280ad1c2b31f8b6c1d5
4
- data.tar.gz: b7a40463bdffe22b23ad0a602b225f1df3041bd8
3
+ metadata.gz: 942379737f4eb3fb24ad2aee9663f11f0a9a0e6a
4
+ data.tar.gz: 26bea5cb199a05a64c86bc10db16439fd44351fe
5
5
  SHA512:
6
- metadata.gz: 20567be380e251d4c16d9b3ba1a3f15feca47c1d3f2130f2f262c0e42c07180bd92179c71ae812dbedf44c779af4ade72c7a1fdaaccab706b876e917d4e477b5
7
- data.tar.gz: 1d2c5ab40e991aa6acd2862d40f2fb44ca0741c4f0c708f7751805340bc941cbeda505d07be1d021b8375381fc952e9fbcbe4f507ad9719cfa311d5b7337139e
6
+ metadata.gz: e83a8ad2f7020b72a74e7932d343228648e50e68cc0c08ab18002de0fafcfff78598c34c4146ae2b2fd5fa1a1764897767f16b845bedd529886e5974b7279a61
7
+ data.tar.gz: 8d50e77a3a902a432f8bdafb559fc9a8f30f5904826893ea68c0bbf04b352ad4eb3620d5af228f544cb8938dc3863b4ad693a5ffc2f103d86723945e0dc7b01e
@@ -1 +1 @@
1
- require 'faraday/http_cache' # rubocop:disable Style/FileName
1
+ require 'faraday/http_cache'
@@ -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
- alias_method :s_maxage, :shared_max_age
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
- headers['Date'] ||= @now.httpdate
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]
@@ -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.0
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-03-24 00:00:00.000000000 Z
11
+ date: 2016-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday