forked from eliotsykes/rails-testing-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuffing_billy_extensions.rb
31 lines (27 loc) · 952 Bytes
/
puffing_billy_extensions.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# See https://github.com/oesmith/puffing-billy/issues/139
module Billy
# puffing-billy/lib/billy/config.rb
class Config
attr_accessor :after_cache_handles_request
end
# puffing-billy/lib/billy/handlers/cache_handler.rb
class CacheHandler
def handle_request(method, url, headers, body)
method = method.downcase
if handles_request?(method, url, headers, body)
if (response = cache.fetch(method, url, body))
Billy.log(:info, "puffing-billy: CACHE #{method} for '#{url}'")
if Billy.config.dynamic_jsonp
replace_response_callback(response, url)
end
if Billy.config.after_cache_handles_request
request = { method: method, url: url, headers: headers, body: body }
Billy.config.after_cache_handles_request.call(request, response)
end
return response
end
end
nil
end
end
end