http_handler_echo_body.erl 488 B

12345678910111213141516171819
  1. %% Feel free to use, reuse and abuse the code in this file.
  2. -module(http_handler_echo_body).
  3. -behaviour(cowboy_http_handler).
  4. -export([init/3, handle/2, terminate/2]).
  5. init({_, http}, Req, _) ->
  6. {ok, Req, undefined}.
  7. handle(Req, State) ->
  8. true = cowboy_req:has_body(Req),
  9. {ok, Body, Req2} = cowboy_req:body(Req),
  10. {Size, Req3} = cowboy_req:body_length(Req2),
  11. Size = byte_size(Body),
  12. {ok, Req4} = cowboy_req:reply(200, [], Body, Req3),
  13. {ok, Req4, State}.
  14. terminate(_, _) ->
  15. ok.