Skip to content

Instantly share code, notes, and snippets.

@l4u
Created July 4, 2012 13:53
Show Gist options
  • Save l4u/3047475 to your computer and use it in GitHub Desktop.
Save l4u/3047475 to your computer and use it in GitHub Desktop.
erlang cowboy 404 onresponse_hook
%% Hook for the above onresponse tests.
onresponse_hook(Status, Headers, Req) ->
case Status of
404 ->
{ok, Html} = file:read_file("www/404.html"),
{ok, Req2} = cowboy_http_req:reply(404, [], Html, Req),
Req2;
_ ->
Req
end.
cowboy:start_listener(http, 100,
cowboy_tcp_transport, [{port, config(http_port)}],
cowboy_http_protocol, [
{dispatch, Dispatch},
{onresponse, fun onresponse_hook/3}
]
), ok.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment