class Faraday::HttpCache
def validate(entry, env)
env - the environment 'Hash' to perform the request.
entry - a stale 'Faraday::HttpCache::Response' retrieved from the cache.
response will be stored (replacing the old one) and used.
and forwarded against the Faraday stack. Otherwise, the freshly new
is marked as 'Not Modified', the previous stored response will be used
existing 'Last-Modified' and 'ETag' headers. If the new response
using the 'If-Modified-Since' and 'If-None-Match' headers with the
Internal: Tries to validated a stored entry back to it's origin server
def validate(entry, env) headers = env[:request_headers] headers['If-Modified-Since'] = entry.last_modified if entry.last_modified headers['If-None-Match'] = entry.etag if entry.etag @app.call(env).on_complete do |requested_env| response = Response.new(requested_env) if response.not_modified? trace :valid updated_response_headers = response.payload[:response_headers] # These headers are not allowed in 304 responses, yet some proxy # servers add them in. Don't override the values from the original # response. updated_response_headers.delete('Content-Type') updated_response_headers.delete('Content-Length') updated_payload = entry.payload updated_payload[:response_headers].update(updated_response_headers) requested_env.update(updated_payload) response = Response.new(updated_payload) else trace :invalid end store(response) end end