lib/async/http/cache/general.rb in async-http-cache-0.1.5 vs lib/async/http/cache/general.rb in async-http-cache-0.2.0
- old
+ new
@@ -29,10 +29,11 @@
module Async
module HTTP
module Cache
class General < ::Protocol::HTTP::Middleware
CACHE_CONTROL = 'cache-control'
+
CONTENT_TYPE = 'content-type'
AUTHORIZATION = 'authorization'
COOKIE = 'cookie'
def initialize(app, store: Store.default)
@@ -89,13 +90,21 @@
def wrap(key, request, response)
if response.status != 200
return response
end
- return Body.wrap(response) do |message, body|
+ if request.head? and body = response.body
+ unless body.empty?
+ Async.logger.warn(self) {"HEAD request resulted in non-empty body!"}
+
+ return response
+ end
+ end
+
+ return Body.wrap(response) do |response, body|
Async.logger.debug(self) {"Updating cache for #{key}..."}
- @store.insert(key, request, Response.new(message, body))
+ @store.insert(key, request, Response.new(response, body))
end
end
def call(request)
key = self.key(request)
@@ -105,10 +114,10 @@
unless cache_control&.no_cache?
if response = @store.lookup(key, request)
Async.logger.debug(self) {"Cache hit for #{key}..."}
@count += 1
- # Create a dup of the response:
+ # Return the cached response:
return response
end
end
unless cache_control&.no_store?