0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Improve errors for when the ProvideCallback is missing

This commit is contained in:
Loïc Hoguin 2018-08-13 17:23:48 +02:00
parent 06a3a93de0
commit 0a5fadc60b
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
3 changed files with 23 additions and 3 deletions

View file

@ -0,0 +1,11 @@
-module(provide_callback_missing_h).
-export([init/2]).
-export([content_types_provided/2]).
init(Req, State) ->
{cowboy_rest, Req, State}.
content_types_provided(Req, State) ->
ct_helper_error_h:ignore(cowboy_rest, set_resp_body, 2),
{[{<<"text/plain">>, provide}], Req, State}.

View file

@ -38,6 +38,7 @@ end_per_group(Name, _) ->
init_dispatch(_) ->
cowboy_router:compile([{'_', [
{"/provide_callback_missing", provide_callback_missing_h, []},
{"/switch_handler", switch_handler_h, run},
{"/switch_handler_opts", switch_handler_h, hibernate}
]}]).
@ -52,6 +53,13 @@ do_decode(Headers, Body) ->
%% Tests.
provide_callback_missing(Config) ->
doc("A 500 response must be sent when the ProvideCallback can't be called."),
ConnPid = gun_open(Config),
Ref = gun:get(ConnPid, "/provide_callback_missing", [{<<"accept-encoding">>, <<"gzip">>}]),
{response, fin, 500, _} = gun:await(ConnPid, Ref),
ok.
switch_handler(Config) ->
doc("Switch REST to loop handler for streaming the response body."),
ConnPid = gun_open(Config),