shelf
shelf copied to clipboard
Implement Cookie() utilities
Originally opened as dart-lang/sdk#18845
This issue was originally filed by [email protected]
It would be really useful to have utilities for managing cookies (parsing cookies, setting cookies)
<img src="https://avatars.githubusercontent.com/u/17034?v=3" align="left" width="48" height="48"hspace="10"> Comment by kevmoo
Removed Type-Defect label. Added Type-Enhancement, Area-Pkg, Pkg-Shelf, Triaged labels.
<img src="https://avatars.githubusercontent.com/u/17034?v=3" align="left" width="48" height="48"hspace="10"> Comment by kevmoo
See also https://code.google.com/p/dart/issues/detail?id=19005
<img src="https://avatars.githubusercontent.com/u/698895?v=3" align="left" width="48" height="48"hspace="10"> Comment by Andersmholmgren
I was going to take a crack at adding cookie based session support to shelf_auth but then ran into this issue with lack of cookie support in shelf so I had to shelve the idea (no pun intended. OK maybe a little)
This comment was originally written by [email protected]
Anders - I implemented very basic session support by copying the dart:io cookie code. See https://github.com/wstrange/shelf_simple_session
<img src="https://avatars.githubusercontent.com/u/698895?v=3" align="left" width="48" height="48"hspace="10"> Comment by Andersmholmgren
Thanks Warren. I'll take a look. I'm not wanting to get involved in any of the session storage side in shelf_auth. Rather just the authentication side (i.e. support establishing / renewing sessions after successful authentication and to authenticate from session based credentials like cookies etc.
Hopefully that will dovetail well with shelf_simple_session
I want! :+1: Moving from HttpServer and the http_server package to Shelf, and hit with the lack of cookie support, where before I was doing e.g. var sessionCookie = request.cookies.firstWhere((cookie) => cookie.name == 'session', orElse: () => null);
.
Yeah would be nice if this one was prioritised
Is there any chance that this could be implemented soon?
This might be something we need the community to drive. @nex3 and I are both pretty slammed.
@kevmoo I would like to take a stab at this. Would having the ability to parse and set a cookie be good enough for a first PR?
Cookie support is available through https://github.com/izolate/shelf-cookie
I did yesterday, a simple (maybe bad code) to handle multi set-cookie
from this
to this
void updateHeader(Response response) {
try {
var newHead = response.headers['set-cookie']
.toString()
.substring(1, response.headers['set-cookie'].toString().length - 1)
.trim();
var newSplit = newHead.split(';');
var XSRF = newSplit[0];
var daniSession = newSplit[4].split(',')[1].trim();
var newCookie = '$XSRF; $daniSession';
myHeaders.addAll(
{'Cookie': '$newCookie'},
);
} catch (e) {
print(e);
}
}