cowboy_req:cast(3)

NAME

cowboy_req:cast - Cast a stream handler event

DESCRIPTION
    cast(Event :: any(), Req :: cowboy_req:req()) -> ok

Cast a stream handler event.

The event will be passed to stream handlers through the info/3 callback.

ARGUMENTS

Event
    The event to be sent to stream handlers.

Req
    The Req object.

RETURN VALUE

The atom ok is always returned. It can be safely ignored.

CHANGELOG
    • 2.7: Function introduced.

EXAMPLES

Read the body using auto mode
    read_body_auto_async(Req) ->
        read_body_auto_async(Req, make_ref(), <<>>).

    read_body_auto_async(Req, Ref, Acc) ->
        cowboy_req:cast({read_body, self(), Ref, auto, infinity}, Req),
        receive
            {request_body, Ref, nofin, Data} ->
                read_body_auto_async(Req, Ref, <<Acc/binary, Data/binary>>);
            {request_body, Ref, fin, _BodyLen, Data} ->
                {ok, <<Acc/binary, Data/binary>>, Req}
        end.

Increase the HTTP/1.1 idle timeout
    cowboy_req:cast({set_options, #{
        idle_timeout => 3600000
    }}, Req).

Add user data to metrics
    cowboy_req:cast({set_options, #{
        metrics_user_data => #{handler => ?MODULE}
    }}, Req).

Enable compression buffering
    cowboy_req:cast({set_options, #{
        compress_buffering => true
    }}, Req).

SEE ALSO

cowboy_req(3), cowboy_stream(3)