OLD | NEW |
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.response; | 5 library shelf.response; |
6 | 6 |
7 import 'dart:convert'; | 7 import 'dart:convert'; |
8 | 8 |
9 import 'package:http_parser/http_parser.dart'; | 9 import 'package:http_parser/http_parser.dart'; |
10 | 10 |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 /// All other context and header values from the [Response] will be included | 231 /// All other context and header values from the [Response] will be included |
232 /// in the copied [Response] unchanged. | 232 /// in the copied [Response] unchanged. |
233 /// | 233 /// |
234 /// [body] is the request body. It may be either a [String] or a | 234 /// [body] is the request body. It may be either a [String] or a |
235 /// [Stream<List<int>>]. | 235 /// [Stream<List<int>>]. |
236 Response change( | 236 Response change( |
237 {Map<String, String> headers, Map<String, Object> context, body}) { | 237 {Map<String, String> headers, Map<String, Object> context, body}) { |
238 headers = updateMap(this.headers, headers); | 238 headers = updateMap(this.headers, headers); |
239 context = updateMap(this.context, context); | 239 context = updateMap(this.context, context); |
240 | 240 |
241 if (body == null) body = this.read(); | 241 if (body == null) body = getBody(this); |
242 | 242 |
243 return new Response(this.statusCode, body: body, headers: headers, | 243 return new Response(this.statusCode, body: body, headers: headers, |
244 context: context); | 244 context: context); |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
248 /// Adds content-type information to [headers]. | 248 /// Adds content-type information to [headers]. |
249 /// | 249 /// |
250 /// Returns a new map without modifying [headers]. This is used to add | 250 /// Returns a new map without modifying [headers]. This is used to add |
251 /// content-type information when creating a 500 response with a default body. | 251 /// content-type information when creating a 500 response with a default body. |
(...skipping 10 matching lines...) Expand all Loading... |
262 /// Converts [location], which may be a [String] or a [Uri], to a [String]. | 262 /// Converts [location], which may be a [String] or a [Uri], to a [String]. |
263 /// | 263 /// |
264 /// Throws an [ArgumentError] if [location] isn't a [String] or a [Uri]. | 264 /// Throws an [ArgumentError] if [location] isn't a [String] or a [Uri]. |
265 String _locationToString(location) { | 265 String _locationToString(location) { |
266 if (location is String) return location; | 266 if (location is String) return location; |
267 if (location is Uri) return location.toString(); | 267 if (location is Uri) return location.toString(); |
268 | 268 |
269 throw new ArgumentError('Response location must be a String or Uri, was ' | 269 throw new ArgumentError('Response location must be a String or Uri, was ' |
270 '"$location".'); | 270 '"$location".'); |
271 } | 271 } |
OLD | NEW |