From 304545f441a1bfb99c17e86e4c90524ddb4d45c4 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Fri, 16 Aug 2019 09:53:15 -0400 Subject: [PATCH] Add writeCookie signature --- example/cookie_signer.dart | 4 +--- lib/src/cookie_signer.dart | 10 +++++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/example/cookie_signer.dart b/example/cookie_signer.dart index 48256f2e..fe444c19 100644 --- a/example/cookie_signer.dart +++ b/example/cookie_signer.dart @@ -26,9 +26,7 @@ main() async { app.get('/getid', (req, res) { // Write the uniqid cookie. var uniqid = rnd.nextInt(65536); - signer.writeCookies(res, [ - Cookie('uniqid', uniqid.toString()), - ]); + signer.writeCookie(res, Cookie('uniqid', uniqid.toString())); // Send a response. res.write('uniqid=$uniqid'); diff --git a/lib/src/cookie_signer.dart b/lib/src/cookie_signer.dart index dbb1f553..4d9c81de 100644 --- a/lib/src/cookie_signer.dart +++ b/lib/src/cookie_signer.dart @@ -79,12 +79,20 @@ class CookieSigner { } } + /// Signs a single [cookie], and adds it to an outgoing + /// [res]ponse. The input [cookie] is not modified. + /// + /// See [createSignedCookie]. + void writeCookie(ResponseContext res, Cookie cookie) { + res.cookies.add(createSignedCookie(cookie)); + } + /// Signs a set of [cookies], and adds them to an outgoing /// [res]ponse. The input [cookies] are not modified. /// /// See [createSignedCookie]. void writeCookies(ResponseContext res, Iterable cookies) { - res.cookies.addAll(cookies.map(createSignedCookie)); + cookies.forEach((c) => writeCookie(res, c)); } /// Returns a new cookie, replacing the value of an input