Commit f77ff748 authored by KT315's avatar KT315
Browse files

Fix fast stream dummy

parent b342b024
defmodule Dummy do
@moduledoc false
@body "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis dictum ligula, ut sagittis nisl malesuada nec. Fusce hendrerit leo augue, nec pretium dolor porta sodales. Sed consequat sed purus eu aliquet. Etiam laoreet nibh vel ex sodales, non egestas lorem tempor. Pellentesque placerat facilisis felis, nec bibendum metus finibus quis. Donec lobortis, sapien at tristique placerat, nibh libero volutpat eros, eget mollis nibh elit et enim. Vestibulum consequat ut lorem sed eleifend. Ut eu dolor ut lectus faucibus rhoncus. Nam vestibulum vitae massa vel congue. Nam ac odio lacus. Nam condimentum ante eget mollis vestibulum. Cras nisi sapien, tempor nec diam at, vulputate cursus odio. Maecenas vitae tellus efficitur arcu mollis ultrices id vitae ex. Suspendisse potenti. Duis nec vestibulum dui. Donec ultricies sit amet lorem eu feugiat. Ut pretium vitae lectus at tempor. Curabitur condimentum arcu varius nulla ultricies, id feugiat odio dictum. Vivamus sollicitudin consectetur nullam."
def init(req, state) do
Process.sleep(trunc(100 * (1.0 + 0.5 * (:rand.uniform() * 2.0 - 1.0))))
req = :cowboy_req.reply(200, %{"content-type" => "text/plain"}, @body, req)
{:ok, req, state}
end
end
......@@ -4,14 +4,6 @@ defmodule Dummy.Application do
use Application
def start(_type, _args) do
dispatch =
:cowboy_router.compile([
{:_,
[
{"/", Dummy, %{}}
]}
])
children = [
%{
id: :dummy,
......@@ -23,7 +15,6 @@ defmodule Dummy.Application do
%{
max_keepalive: 1_000,
max_received_frame_rate: {1_000_000, 1},
env: %{dispatch: dispatch},
stream_handlers: [Dummy.FastStream]
}
]},
......
......@@ -3,16 +3,17 @@ defmodule Dummy.FastStream do
@behaviour :cowboy_stream
def init(_stream_id, req, opts) do
env = Map.get(opts, :env, %{})
{:ok, req, %{handler: handler, handler_opts: handler_opts}} = :cowboy_router.execute(req, env)
@body "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis dictum ligula, ut sagittis nisl malesuada nec. Fusce hendrerit leo augue, nec pretium dolor porta sodales. Sed consequat sed purus eu aliquet. Etiam laoreet nibh vel ex sodales, non egestas lorem tempor. Pellentesque placerat facilisis felis, nec bibendum metus finibus quis. Donec lobortis, sapien at tristique placerat, nibh libero volutpat eros, eget mollis nibh elit et enim. Vestibulum consequat ut lorem sed eleifend. Ut eu dolor ut lectus faucibus rhoncus. Nam vestibulum vitae massa vel congue. Nam ac odio lacus. Nam condimentum ante eget mollis vestibulum. Cras nisi sapien, tempor nec diam at, vulputate cursus odio. Maecenas vitae tellus efficitur arcu mollis ultrices id vitae ex. Suspendisse potenti. Duis nec vestibulum dui. Donec ultricies sit amet lorem eu feugiat. Ut pretium vitae lectus at tempor. Curabitur condimentum arcu varius nulla ultricies, id feugiat odio dictum. Vivamus sollicitudin consectetur nullam."
{:ok, _req, _state} = Kernel.apply(handler, :init, [req, handler_opts])
def init(_stream_id, req, _opts) do
Process.sleep(trunc(100 * (1.0 + 0.5 * (:rand.uniform() * 2.0 - 1.0))))
receive do
{_, msg} ->
{[msg, :stop], :undefined}
end
headers = %{
"content-type" => "text/plain",
"content-length" => Integer.to_string(byte_size(@body))
}
{[{:response, 200, :cowboy_req.response_headers(headers, req), @body}, :stop], :undefined}
end
def data(stream_id, is_fin, data, next) do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment