@@ -18,17 +18,32 @@ class Response {
1818 encoding: encoding,
1919 ),
2020 );
21+ Response ._(this ._response);
2122
2223 /// Create a [Response] with a stream of bytes.
24+ ///
25+ /// If [bufferOutput] is `true` (the default), streamed responses will be
26+ /// buffered to improve performance. If `false` , all chunks will be pushed
27+ /// over the wire as they're received. Note that, disabling buffering of the
28+ /// output can result in very poor performance, when writing many small
29+ /// chunks.
30+ ///
31+ /// See also:
32+ ///
33+ /// * [HttpResponse.bufferOutput] (https://api.flutter.dev/flutter/dart-io/HttpResponse/bufferOutput.html)
2334 Response .stream ({
2435 int statusCode = 200 ,
2536 Stream <List <int >>? body,
2637 Map <String , Object >? headers,
38+ bool bufferOutput = true ,
2739 }) : this ._(
2840 shelf.Response (
2941 statusCode,
3042 body: body,
3143 headers: headers,
44+ context: ! bufferOutput
45+ ? {Response .shelfBufferOutputContextKey: bufferOutput}
46+ : null ,
3247 ),
3348 );
3449
@@ -80,7 +95,15 @@ class Response {
8095 encoding: encoding,
8196 );
8297
83- Response ._(this ._response);
98+ /// A [shelf.Response.context] key used to determine if if the
99+ /// [HttpResponse.bufferOutput] should be enabled or disabled.
100+ ///
101+ /// See also:
102+ ///
103+ /// * [shelf_io library] (https://pub.dev/documentation/shelf/latest/shelf_io/shelf_io-library.html)
104+ /// * [HttpResponse.bufferOutput] (https://api.flutter.dev/flutter/dart-io/HttpResponse/bufferOutput.html)
105+ @visibleForTesting
106+ static const shelfBufferOutputContextKey = 'shelf.io.buffer_output' ;
84107
85108 shelf.Response _response;
86109
@@ -91,6 +114,12 @@ class Response {
91114 /// The returned map is unmodifiable.
92115 Map <String , String > get headers => _response.headers;
93116
117+ /// Extra context that can be used by for middleware and handlers.
118+ ///
119+ /// The value is immutable.
120+ @visibleForTesting
121+ Map <String , Object > get context => _response.context;
122+
94123 /// Returns a [Stream] representing the body.
95124 Stream <List <int >> bytes () => _response.read ();
96125
0 commit comments