shelf_cookie 1.1.1

Dart native
Flutter Android iOS

Cookie parser middleware for the Shelf ecosystem. Reads cookies in request, sets cookies in response.

example/example.dart

import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_cookie/shelf_cookie.dart';

void main() {
  /// Request contains cookie header.
  /// e.g. 'cookie': 'ping=foo'
  var handler = const shelf.Pipeline()
      .addMiddleware(cookieParser())
      .addHandler((req) async {
    CookieParser cookies = req.context['cookies'];
    if (cookies.get('ping') != null) {
      // Clear cookies because Shelf currently only supports
      // a single `Set-Cookie` header in response.
      cookies.clear();
      cookies.set('pong', 'bar', secure: true);
    }

    // Response will set cookie header.
    // e.g. 'set-cookie': 'pong=bar; Secure; HttpOnly'
    return shelf.Response.ok('check your cookies');
  });

  io.serve(handler, 'localhost', 8080).then((server) {
    print('Serving at http://${server.address.host}:${server.port}');
  });
}
1
likes
95
pub points
67%
popularity

Cookie parser middleware for the Shelf ecosystem. Reads cookies in request, sets cookies in response.

Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

Uploader

izolate@gmail.com

License

MIT (LICENSE)

Dependencies

shelf

More

Packages that depend on shelf_cookie