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