fast_stream.ex 864 Bytes
Newer Older
KT315's avatar
KT315 committed
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 32 33
defmodule Dummy.FastStream do
  @moduledoc false

  @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)

    {:ok, _req, _state} = Kernel.apply(handler, :init, [req, handler_opts])

    receive do
      {_, msg} ->
        {[msg, :stop], :undefined}
    end
  end

  def data(stream_id, is_fin, data, next) do
    :cowboy_stream.data(stream_id, is_fin, data, next)
  end

  def info(stream_id, info, next) do
    :cowboy_stream.info(stream_id, info, next)
  end

  def terminate(stream_id, reason, next) do
    :cowboy_stream.terminate(stream_id, reason, next)
  end

  def early_error(stream_id, reason, partial_req, resp, opts) do
    :cowboy_stream.early_error(stream_id, reason, partial_req, resp, opts)
  end
end