ws_terminate_h.erl 761 B

12345678910111213141516171819202122232425262728293031323334
  1. %% This module sends a message with terminate arguments to the test case process.
  2. -module(ws_terminate_h).
  3. -behavior(cowboy_websocket).
  4. -export([init/2]).
  5. -export([websocket_init/1]).
  6. -export([websocket_handle/2]).
  7. -export([websocket_info/2]).
  8. -export([terminate/3]).
  9. -record(state, {
  10. pid
  11. }).
  12. init(Req, _) ->
  13. Pid = list_to_pid(binary_to_list(cowboy_req:header(<<"x-test-pid">>, Req))),
  14. Opts = case cowboy_req:qs(Req) of
  15. <<"req_filter">> -> #{req_filter => fun(_) -> filtered end};
  16. _ -> #{}
  17. end,
  18. {cowboy_websocket, Req, #state{pid=Pid}, Opts}.
  19. websocket_init(State) ->
  20. {ok, State}.
  21. websocket_handle(_, State) ->
  22. {ok, State}.
  23. websocket_info(_, State) ->
  24. {ok, State}.
  25. terminate(Reason, Req, #state{pid=Pid}) ->
  26. Pid ! {terminate, Reason, Req}.