From 81cc99d10bab86369f4ae7ea0db948ffad1239d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 13 Oct 2011 16:16:53 +0200 Subject: Add shortcuts to reply functions New functions are reply/2, reply/3, chunked_reply/2 in cowboy_http_req. --- src/cowboy_http_req.erl | 18 +++++++++++++++++- test/chunked_handler.erl | 2 +- test/http_handler_init_shutdown.erl | 2 +- test/http_handler_long_polling.erl | 2 +- test/websocket_handler_init_shutdown.erl | 2 +- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/cowboy_http_req.erl b/src/cowboy_http_req.erl index 63b196e..a7b0533 100644 --- a/src/cowboy_http_req.erl +++ b/src/cowboy_http_req.erl @@ -37,7 +37,8 @@ ]). %% Request Body API. -export([ - reply/4, chunked_reply/3, chunk/2 + reply/2, reply/3, reply/4, + chunked_reply/2, chunked_reply/3, chunk/2 ]). %% Response API. -export([ @@ -312,6 +313,16 @@ body_qs(Req) -> %% Response API. +%% @equiv reply(Status, [], [], Req) +-spec reply(http_status(), #http_req{}) -> {ok, #http_req{}}. +reply(Status, Req) -> + reply(Status, [], [], Req). + +%% @equiv reply(Status, Headers, [], Req) +-spec reply(http_status(), http_headers(), #http_req{}) -> {ok, #http_req{}}. +reply(Status, Headers, Req) -> + reply(Status, Headers, [], Req). + %% @doc Send a reply to the client. -spec reply(http_status(), http_headers(), iodata(), #http_req{}) -> {ok, #http_req{}}. @@ -332,6 +343,11 @@ reply(Status, Headers, Body, Req=#http_req{socket=Socket, end, {ok, Req#http_req{connection=RespConn, resp_state=done}}. +%% @equiv chunked_reply(Status, [], Req) +-spec chunked_reply(http_status(), #http_req{}) -> {ok, #http_req{}}. +chunked_reply(Status, Req) -> + chunked_reply(Status, [], Req). + %% @doc Initiate the sending of a chunked reply to the client. %% @see cowboy_http_req:chunk/2 -spec chunked_reply(http_status(), http_headers(), #http_req{}) diff --git a/test/chunked_handler.erl b/test/chunked_handler.erl index 97ce27c..d246d51 100644 --- a/test/chunked_handler.erl +++ b/test/chunked_handler.erl @@ -8,7 +8,7 @@ init({_Transport, http}, Req, _Opts) -> {ok, Req, undefined}. handle(Req, State) -> - {ok, Req2} = cowboy_http_req:chunked_reply(200, [], Req), + {ok, Req2} = cowboy_http_req:chunked_reply(200, Req), cowboy_http_req:chunk("chunked_handler\r\n", Req2), cowboy_http_req:chunk("works fine!", Req2), {ok, Req2, State}. diff --git a/test/http_handler_init_shutdown.erl b/test/http_handler_init_shutdown.erl index a5930ca..732ca1d 100644 --- a/test/http_handler_init_shutdown.erl +++ b/test/http_handler_init_shutdown.erl @@ -6,7 +6,7 @@ init({_Transport, http}, Req, _Opts) -> Req2 = cowboy_http_req:reply(<<"666 Init Shutdown Testing">>, - [{'Connection', <<"close">>}], [], Req), + [{'Connection', <<"close">>}], Req), {shutdown, Req2, undefined}. handle(Req, State) -> diff --git a/test/http_handler_long_polling.erl b/test/http_handler_long_polling.erl index 374e244..e838619 100644 --- a/test/http_handler_long_polling.erl +++ b/test/http_handler_long_polling.erl @@ -12,7 +12,7 @@ handle(_Req, _State) -> exit(badarg). info(timeout, Req, 0) -> - {ok, Req2} = cowboy_http_req:reply(102, [], [], Req), + {ok, Req2} = cowboy_http_req:reply(102, Req), {ok, Req2, 0}; info(timeout, Req, State) -> erlang:send_after(500, self(), timeout), diff --git a/test/websocket_handler_init_shutdown.erl b/test/websocket_handler_init_shutdown.erl index ad76336..2d52cbd 100644 --- a/test/websocket_handler_init_shutdown.erl +++ b/test/websocket_handler_init_shutdown.erl @@ -17,7 +17,7 @@ terminate(_Req, _State) -> exit(badarg). websocket_init(_TransportName, Req, _Opts) -> - Req2 = cowboy_http_req:reply(403, [], [], Req), + Req2 = cowboy_http_req:reply(403, Req), {shutdown, Req2}. websocket_handle(_Frame, _Req, _State) -> -- cgit v1.2.3