diff options
author | Loïc Hoguin <[email protected]> | 2011-12-07 11:54:57 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2011-12-07 11:54:57 +0100 |
commit | ce92ab1e633408b0d6b2d4bb4ba61d965208ef3c (patch) | |
tree | a41bcfb2daca5cfbf35840da216a5029ba99b381 | |
parent | a12a910341dd22bd27096b50edf3d9820bc90384 (diff) | |
download | cowboy-ce92ab1e633408b0d6b2d4bb4ba61d965208ef3c.tar.gz cowboy-ce92ab1e633408b0d6b2d4bb4ba61d965208ef3c.tar.bz2 cowboy-ce92ab1e633408b0d6b2d4bb4ba61d965208ef3c.zip |
Add cowboy_http_req:set_resp_cookie/4
Pretty much just an alias for a combination of set_resp_header and cookie.
-rw-r--r-- | src/cowboy_http_req.erl | 9 | ||||
-rw-r--r-- | test/http_SUITE.erl | 3 | ||||
-rw-r--r-- | test/http_handler_set_resp.erl | 4 |
3 files changed, 13 insertions, 3 deletions
diff --git a/src/cowboy_http_req.erl b/src/cowboy_http_req.erl index d5ee3fa..e4cb33e 100644 --- a/src/cowboy_http_req.erl +++ b/src/cowboy_http_req.erl @@ -37,7 +37,7 @@ ]). %% Request Body API. -export([ - set_resp_header/3, set_resp_body/2, + set_resp_cookie/4, set_resp_header/3, set_resp_body/2, has_resp_header/2, has_resp_body/1, reply/2, reply/3, reply/4, chunked_reply/2, chunked_reply/3, chunk/2, @@ -361,6 +361,13 @@ body_qs(Req) -> %% Response API. +%% @doc Add a cookie header to the response. +-spec set_resp_cookie(binary(), binary(), [cowboy_cookies:cookie_option()], + #http_req{}) -> {ok, #http_req{}}. +set_resp_cookie(Name, Value, Options, Req) -> + {HeaderName, HeaderValue} = cowboy_cookies:cookie(Name, Value, Options), + set_resp_header(HeaderName, HeaderValue, Req). + %% @doc Add a header to the response. -spec set_resp_header(http_header(), iodata(), #http_req{}) -> {ok, #http_req{}}. diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl index 2db6ff4..8fdc52d 100644 --- a/test/http_SUITE.erl +++ b/test/http_SUITE.erl @@ -505,7 +505,8 @@ set_resp_header(Config) -> ok = gen_tcp:send(Socket, "GET /set_resp/header HTTP/1.1\r\n" "Host: localhost\r\nConnection: close\r\n\r\n"), {ok, Data} = gen_tcp:recv(Socket, 0, 6000), - {_Start, _Length} = binary:match(Data, <<"Vary: Accept">>). + {_, _} = binary:match(Data, <<"Vary: Accept">>), + {_, _} = binary:match(Data, <<"Set-Cookie: ">>). set_resp_overwrite(Config) -> {port, Port} = lists:keyfind(port, 1, Config), diff --git a/test/http_handler_set_resp.erl b/test/http_handler_set_resp.erl index 6aca73d..83d48c0 100644 --- a/test/http_handler_set_resp.erl +++ b/test/http_handler_set_resp.erl @@ -13,7 +13,9 @@ init({_Transport, http}, Req, Opts) -> {ok, Req3} = cowboy_http_req:set_resp_body(Body, Req2), {ok, Req4} = cowboy_http_req:set_resp_header( <<"X-Cowboy-Test">>, <<"ok">>, Req3), - {ok, Req4, undefined}. + {ok, Req5} = cowboy_http_req:set_resp_cookie( + <<"cake">>, <<"lie">>, [], Req4), + {ok, Req5, undefined}. handle(Req, State) -> case cowboy_http_req:has_resp_header(<<"X-Cowboy-Test">>, Req) of |