Sha256: fd8fb5f84ac4ba27b23af5647a9fb51a93a27cdcd181538df7ecd85276caccdf
Contents?: true
Size: 1.42 KB
Versions: 3
Compression:
Stored size: 1.42 KB
Contents
module Billy class RequestHandler extend Forwardable include Handler def_delegators :stub_handler, :stub def handlers @handlers ||= { :stubs => StubHandler.new, :cache => CacheHandler.new, :proxy => ProxyHandler.new } end def handle_request(method, url, headers, body) # Process the handlers by order of importance [:stubs, :cache, :proxy].each do |key| if (response = handlers[key].handle_request(method, url, headers, body)) return response end end body_msg = method == 'post' ? " with body '#{body}'" : '' { :error => "Connection to #{url}#{body_msg} not cached and new http connections are disabled" } end def handles_request?(method, url, headers, body) [:stubs, :cache, :proxy].each do |key| return true if handlers[key].handles_request?(method, url, headers, body) end false end def reset handlers.each_value do |handler| handler.reset end end def reset_stubs handlers[:stubs].reset end def reset_cache handlers[:cache].reset end def restore_cache warn "[DEPRECATION] `restore_cache` is deprecated as cache files are dynamically checked. Use `reset_cache` if you just want to clear the cache." reset_cache end private def stub_handler handlers[:stubs] end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
puffing-billy-0.4.1 | lib/billy/handlers/request_handler.rb |
puffing-billy-0.4.0 | lib/billy/handlers/request_handler.rb |
puffing-billy-0.3.0 | lib/billy/handlers/request_handler.rb |