Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Unified Diff: pkg/shelf/lib/src/message.dart

Issue 239183005: Add a context field to Message in shelf. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/shelf/CHANGELOG.md ('k') | pkg/shelf/lib/src/request.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/shelf/lib/src/message.dart
diff --git a/pkg/shelf/lib/src/message.dart b/pkg/shelf/lib/src/message.dart
index ad64d10ea31604ae930400e60e4cb3955ffcbc5d..1b2e966c4660b3375519c985a459362257e00408 100644
--- a/pkg/shelf/lib/src/message.dart
+++ b/pkg/shelf/lib/src/message.dart
@@ -20,6 +20,19 @@ abstract class Message {
/// The value is immutable.
final Map<String, String> headers;
+ /// Extra context that can be used by for middleware and handlers.
+ ///
+ /// For requests, this is used to pass data to inner middleware and handlers;
+ /// for responses, it's used to pass data to outer middleware and handlers.
+ ///
+ /// Context properties that are used by a particular package should begin with
+ /// that package's name followed by a period. For example, if [logRequests]
+ /// wanted to take a prefix, its property name would be `"shelf.prefix"`,
+ /// since it's in the `shelf` package.
+ ///
+ /// The value is immutable.
+ final Map<String, Object> context;
+
/// The streaming body of the message.
///
/// This can be read via [read] or [readAsString].
@@ -28,8 +41,11 @@ abstract class Message {
/// Creates a new [Message].
///
/// If [headers] is `null`, it is treated as empty.
- Message(this._body, {Map<String, String> headers})
- : this.headers = _getIgnoreCaseMapView(headers);
+ Message(this._body, {Map<String, String> headers,
+ Map<String, Object> context})
+ : this.headers = _getIgnoreCaseMapView(headers),
+ this.context = new pc.UnmodifiableMapView(
+ context == null ? const {} : new Map.from(context));
/// The contents of the content-length field in [headers].
///
« no previous file with comments | « pkg/shelf/CHANGELOG.md ('k') | pkg/shelf/lib/src/request.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698