websocket_handler_init_shutdown.erl 756 B

123456789101112131415161718192021222324252627282930
  1. %% Feel free to use, reuse and abuse the code in this file.
  2. -module(websocket_handler_init_shutdown).
  3. -behaviour(cowboy_http_handler).
  4. -behaviour(cowboy_http_websocket_handler).
  5. -export([init/3, handle/2, terminate/2]).
  6. -export([websocket_init/3, websocket_handle/3,
  7. websocket_info/3, websocket_terminate/3]).
  8. init(_Any, _Req, _Opts) ->
  9. {upgrade, protocol, cowboy_http_websocket}.
  10. handle(_Req, _State) ->
  11. exit(badarg).
  12. terminate(_Req, _State) ->
  13. exit(badarg).
  14. websocket_init(_TransportName, Req, _Opts) ->
  15. {ok, Req2} = cowboy_http_req:reply(403, Req),
  16. {shutdown, Req2}.
  17. websocket_handle(_Frame, _Req, _State) ->
  18. exit(badarg).
  19. websocket_info(_Info, _Req, _State) ->
  20. exit(badarg).
  21. websocket_terminate(_Reason, _Req, _State) ->
  22. exit(badarg).