shelf_cookie 1.1.0 copy "shelf_cookie: ^1.1.0" to clipboard
shelf_cookie: ^1.1.0 copied to clipboard

outdated

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}');
  });
}
6
likes
35
points
36
downloads

Publisher

unverified uploader

Weekly Downloads

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

Repository (GitHub)

Documentation

Documentation

License

MIT (license)

Dependencies

shelf

More

Packages that depend on shelf_cookie