shelf icon indicating copy to clipboard operation
shelf copied to clipboard

Implement Cookie() utilities

Open DartBot opened this issue 9 years ago • 12 comments

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)  

DartBot avatar Jun 05 '15 23:06 DartBot

<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.

DartBot avatar Jun 05 '15 23:06 DartBot

<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

DartBot avatar Jun 05 '15 23:06 DartBot

<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)

DartBot avatar Jun 05 '15 23:06 DartBot

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

DartBot avatar Jun 05 '15 23:06 DartBot

<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

DartBot avatar Jun 05 '15 23:06 DartBot

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);.

davenotik avatar Oct 23 '15 13:10 davenotik

Yeah would be nice if this one was prioritised

Andersmholmgren avatar Oct 25 '15 03:10 Andersmholmgren

Is there any chance that this could be implemented soon?

enyo avatar Nov 08 '16 15:11 enyo

This might be something we need the community to drive. @nex3 and I are both pretty slammed.

kevmoo avatar Nov 08 '16 16:11 kevmoo

@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?

allentv avatar May 10 '20 14:05 allentv

Cookie support is available through https://github.com/izolate/shelf-cookie

allentv avatar Aug 09 '20 20:08 allentv

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);
    }
  }

allasca avatar Dec 24 '21 02:12 allasca