Add writeCookie signature
This commit is contained in:
parent
c045da3e03
commit
304545f441
2 changed files with 10 additions and 4 deletions
|
@ -26,9 +26,7 @@ main() async {
|
||||||
app.get('/getid', (req, res) {
|
app.get('/getid', (req, res) {
|
||||||
// Write the uniqid cookie.
|
// Write the uniqid cookie.
|
||||||
var uniqid = rnd.nextInt(65536);
|
var uniqid = rnd.nextInt(65536);
|
||||||
signer.writeCookies(res, [
|
signer.writeCookie(res, Cookie('uniqid', uniqid.toString()));
|
||||||
Cookie('uniqid', uniqid.toString()),
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Send a response.
|
// Send a response.
|
||||||
res.write('uniqid=$uniqid');
|
res.write('uniqid=$uniqid');
|
||||||
|
|
|
@ -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
|
/// Signs a set of [cookies], and adds them to an outgoing
|
||||||
/// [res]ponse. The input [cookies] are not modified.
|
/// [res]ponse. The input [cookies] are not modified.
|
||||||
///
|
///
|
||||||
/// See [createSignedCookie].
|
/// See [createSignedCookie].
|
||||||
void writeCookies(ResponseContext res, Iterable<Cookie> cookies) {
|
void writeCookies(ResponseContext res, Iterable<Cookie> cookies) {
|
||||||
res.cookies.addAll(cookies.map(createSignedCookie));
|
cookies.forEach((c) => writeCookie(res, c));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a new cookie, replacing the value of an input
|
/// Returns a new cookie, replacing the value of an input
|
||||||
|
|
Loading…
Reference in a new issue