e3f0ec8ee0
* Handle binary resp_status from Cowboy and rename http.status to http.status_code * Fix test to use http.status_code as well * Handle resp_status could be undefined but not error - This could be due to websocket upgrade request. * Rename Status1 and transform_status to a more concise naming * Add test case for handling binary response code * Fix syntax and failing tests * Always convert cowboy status to status code * Set otel span status as error when status code >= 500
26 lines
864 B
Erlang
26 lines
864 B
Erlang
-module(test_h).
|
|
-behaviour(cowboy_handler).
|
|
|
|
-export([init/2]).
|
|
|
|
init(_, failure) ->
|
|
error(failure);
|
|
init(Req, success = Opts) ->
|
|
{ok, cowboy_req:reply(200, #{}, <<"Hello world!">>, Req), Opts};
|
|
init(Req, binary_status_code = Opts) ->
|
|
{ok, cowboy_req:reply(<<"200 OK">>, #{}, <<"Hello world!">>, Req), Opts};
|
|
init(Req, slow = Opts) ->
|
|
timer:sleep(200),
|
|
{ok, cowboy_req:reply(200, #{}, <<"I'm slow">>, Req), Opts};
|
|
init(Req0, chunked = Opts) ->
|
|
Req = cowboy_req:stream_reply(200, Req0),
|
|
cowboy_req:stream_body("Hello\r\n", nofin, Req),
|
|
cowboy_req:stream_body("World\r\n", fin, Req),
|
|
{ok, Req, Opts};
|
|
init(Req0, chunked_slow = Opts) ->
|
|
Req = cowboy_req:stream_reply(200, Req0),
|
|
cowboy_req:stream_body("Hello\r\n", nofin, Req),
|
|
timer:sleep(200),
|
|
cowboy_req:stream_body("World\r\n", fin, Req),
|
|
{ok, Req, Opts}.
|