Sha256: 196fc96a786f31afb974bef64a95ffae4fec35266cbd745051e2446972c7d4e4
Contents?: true
Size: 1.18 KB
Versions: 2
Compression:
Stored size: 1.18 KB
Contents
# encoding: utf-8 class SpecHandler def serve(request, served) served.fulfill(response_for(request)) end private def response_for(request) case request.uri when '/sleep' then sleep_response when '/close' then close_response when '/streaming' then streaming_response else echo_response(request) end end def echo_response(request) HTTPkit::Response.new(200, { 'Content-Type' => 'text/plain' }, request.uri) end def sleep_response SpecHelper.async_sleep(0.01) HTTPkit::Response.new(200, { 'Content-Type' => 'text/plain' }, '/sleep') end def close_response HTTPkit::Response.new(200, { 'Content-Type' => 'text/plain', 'Connection' => 'close' }, '/close') end def streaming_response response = HTTPkit::Response.new(200, { 'Content-Type' => 'text/plain' }, HTTPkit::Body.new) SpecHelper.defer do %w[foo bar baz].each do |chunk| SpecHelper.tick(2) response.body.write(chunk) end response.close end response end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
httpkit-0.6.0 | spec/support/handler.rb |
httpkit-0.6.0.pre.5 | spec/support/handler.rb |