[doc/io] Add documentation for HttpSession
Bug:https://github.com/dart-lang/sdk/issues/16228
Change-Id: I4e70c0b15af7325d9bfaba6dcee6b3a4c68639c1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330169
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Brian Quinlan <bquinlan@google.com>
diff --git a/sdk/lib/_http/http.dart b/sdk/lib/_http/http.dart
index 15597fc..0f80b46 100644
--- a/sdk/lib/_http/http.dart
+++ b/sdk/lib/_http/http.dart
@@ -641,6 +641,33 @@
}
/// The [session][HttpRequest.session] of an [HttpRequest].
+///
+/// Stores arbitrary information about a browser session on the server. This
+/// information is stored in memory so it will be lost when the server exits.
+///
+/// A cookie named "DARTSESSID" is stored on the browser to associate the
+/// `HttpSession` with a particular client.
+///
+/// ```dart
+/// import 'dart:io';
+///
+/// void main() async {
+/// HttpServer.bind("localhost", 8080).then((server) {
+/// server.listen((request) {
+/// final session = request.session;
+/// if (session.isNew) {
+/// session["cart"] = [];
+/// }
+/// if (request.uri.queryParameters['buy'] != null) {
+/// final item = request.uri.queryParameters['buy'];
+/// session["cart"].add(item);
+/// }
+/// session["cart"].cast<String>().forEach(request.response.writeln);
+/// request.response.close();
+/// });
+/// });
+/// }
+/// ```
abstract interface class HttpSession implements Map {
/// The id of the current session.
String get id;
diff --git a/tests/standalone/io/http_session_test.dart b/tests/standalone/io/http_session_test.dart
index e410498..48587a4 100644
--- a/tests/standalone/io/http_session_test.dart
+++ b/tests/standalone/io/http_session_test.dart
@@ -119,7 +119,6 @@
Expect.isTrue(session.containsKey("data"));
Expect.equals("some data", session["data"]);
}
- ;
request.response.close();
});