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

Side by Side Diff: pkg/shelf/lib/src/message.dart

Issue 226263007: issue 17992 Added extra params to message (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/shelf/lib/src/request.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library shelf.message; 5 library shelf.message;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:collection/wrappers.dart'; 10 import 'package:collection/wrappers.dart';
11 import 'package:http_parser/http_parser.dart'; 11 import 'package:http_parser/http_parser.dart';
12 import 'package:stack_trace/stack_trace.dart'; 12 import 'package:stack_trace/stack_trace.dart';
13 13
14 /// Represents logic shared between [Request] and [Response]. 14 /// Represents logic shared between [Request] and [Response].
15 abstract class Message { 15 abstract class Message {
16 /// The HTTP headers. 16 /// The HTTP headers.
17 /// 17 ///
18 /// The value is immutable. 18 /// The value is immutable.
19 final Map<String, String> headers; 19 final Map<String, String> headers;
20 20
21 /// The streaming body of the message. 21 /// The streaming body of the message.
22 /// 22 ///
23 /// This can be read via [read] or [readAsString]. 23 /// This can be read via [read] or [readAsString].
24 final Stream<List<int>> _body; 24 final Stream<List<int>> _body;
25 25
26 Message(UnmodifiableMapView<String, String> headers, this._body) 26 /// Extra parameters for handlers to pass data to downstream handlers
nweiz 2014/04/08 21:33:50 I don't know that everyone will have the same intu
andersmholmgren 2014/04/08 22:16:36 My bad, clearly I was thinking of request context
27 : this.headers = headers; 27 /// TODO: less sucky name
28 ///
29 /// The value is immutable.
30 final Map<String, Object> extraParams;
nweiz 2014/04/08 21:33:50 I like "context" as a name here.
andersmholmgren 2014/04/08 22:16:36 +1. That's the best name. It came to me a day afte
31
32
33 Message(UnmodifiableMapView<String, String> headers, this._body,
34 [ UnmodifiableMapView<String, Object> extraParams ])
35 : this.headers = headers,
36 this.extraParams = extraParams;
28 37
29 /// The contents of the content-length field in [headers]. 38 /// The contents of the content-length field in [headers].
30 /// 39 ///
31 /// If not set, `null`. 40 /// If not set, `null`.
32 int get contentLength { 41 int get contentLength {
33 if (_contentLengthCache != null) return _contentLengthCache; 42 if (_contentLengthCache != null) return _contentLengthCache;
34 if (!headers.containsKey('content-length')) return null; 43 if (!headers.containsKey('content-length')) return null;
35 _contentLengthCache = int.parse(headers['content-length']); 44 _contentLengthCache = int.parse(headers['content-length']);
36 return _contentLengthCache; 45 return _contentLengthCache;
37 } 46 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 /// Otherwise the encoding is taken from the Content-Type header. If that 94 /// Otherwise the encoding is taken from the Content-Type header. If that
86 /// doesn't exist or doesn't have a "charset" parameter, UTF-8 is used. 95 /// doesn't exist or doesn't have a "charset" parameter, UTF-8 is used.
87 /// 96 ///
88 /// This calls [read] internally, which can only be called once. 97 /// This calls [read] internally, which can only be called once.
89 Future<String> readAsString([Encoding encoding]) { 98 Future<String> readAsString([Encoding encoding]) {
90 if (encoding == null) encoding = this.encoding; 99 if (encoding == null) encoding = this.encoding;
91 if (encoding == null) encoding = UTF8; 100 if (encoding == null) encoding = UTF8;
92 return Chain.track(encoding.decodeStream(read())); 101 return Chain.track(encoding.decodeStream(read()));
93 } 102 }
94 } 103 }
OLDNEW
« no previous file with comments | « no previous file | pkg/shelf/lib/src/request.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698