Skip to content

Instantly share code, notes, and snippets.

@mje113
Created July 3, 2014 14:17
Show Gist options
  • Save mje113/43eefdeef1df6d4b57f4 to your computer and use it in GitHub Desktop.
Save mje113/43eefdeef1df6d4b57f4 to your computer and use it in GitHub Desktop.
class MockHystrixStream
HEADERS = {
'Content-Type' => 'text/event-stream;charset=UTF-8',
'Cache-Control' => 'no-cache, no-store, max-age=0, must-revalidate',
'Pragma' => 'no-cache',
'Transfer-Encoding' => 'chunked'
}
DATA = open(Rails.root + 'data/hystrix.stream').read.split("\n\n")
def call(env)
env['rack.hijack'].call
io = env['rack.hijack_io']
begin
io.write("HTTP/1.1 200 OK\r\n")
HEADERS.each_pair do |k, v|
io.write("#{k}: #{v}\r\n")
end
io.write("\r\n")
# io.flush
DATA.each do |line|
io.write("#{line}\n\n")
io.flush
sleep 0.5
end
rescue Errno::EPIPE
# Client closed connection
ensure
io.close
end
[-1, {}, []]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment