Current section
Files
Jump to
Current section
Files
src/refrakt@flash.erl
-module(refrakt@flash).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/refrakt/flash.gleam").
-export([set_flash/4, get_flash/2]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-file("src/refrakt/flash.gleam", 20).
?DOC(" Set a flash message on a response. Uses signed cookies with a short TTL.\n").
-spec set_flash(
gleam@http@response:response(wisp:body()),
gleam@http@request:request(wisp@internal:connection()),
binary(),
binary()
) -> gleam@http@response:response(wisp:body()).
set_flash(Response, Req, Key, Message) ->
Cookie_name = <<"_flash_"/utf8, Key/binary>>,
wisp:set_cookie(Response, Req, Cookie_name, Message, signed, 60).
-file("src/refrakt/flash.gleam", 31).
?DOC(" Read a flash message from a request. Returns the message if present.\n").
-spec get_flash(
gleam@http@request:request(wisp@internal:connection()),
binary()
) -> {ok, binary()} | {error, nil}.
get_flash(Req, Key) ->
Cookie_name = <<"_flash_"/utf8, Key/binary>>,
wisp:get_cookie(Req, Cookie_name, signed).