| 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:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'package:http_parser/http_parser.dart'; | 10 import 'package:http_parser/http_parser.dart'; |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 269 } |
| 270 | 270 |
| 271 var contentType = new MediaType.parse(headers['content-type']) | 271 var contentType = new MediaType.parse(headers['content-type']) |
| 272 .change(parameters: {'charset': encoding.name}); | 272 .change(parameters: {'charset': encoding.name}); |
| 273 return _addHeader(headers, 'content-type', contentType.toString()); | 273 return _addHeader(headers, 'content-type', contentType.toString()); |
| 274 } | 274 } |
| 275 | 275 |
| 276 /// Adds a header with [name] and [value] to [headers], which may be null. | 276 /// Adds a header with [name] and [value] to [headers], which may be null. |
| 277 /// | 277 /// |
| 278 /// Returns a new map without modifying [headers]. | 278 /// Returns a new map without modifying [headers]. |
| 279 Map<String, String> _addHeader(Map<String, String> headers, String name, | 279 Map<String, String> _addHeader( |
| 280 String value) { | 280 Map<String, String> headers, String name, String value) { |
| 281 headers = headers == null ? {} : new Map.from(headers); | 281 headers = headers == null ? {} : new Map.from(headers); |
| 282 headers[name] = value; | 282 headers[name] = value; |
| 283 return headers; | 283 return headers; |
| 284 } | 284 } |
| 285 | 285 |
| 286 /// Adds content-type information to [headers]. | 286 /// Adds content-type information to [headers]. |
| 287 /// | 287 /// |
| 288 /// Returns a new map without modifying [headers]. This is used to add | 288 /// Returns a new map without modifying [headers]. This is used to add |
| 289 /// content-type information when creating a 500 response with a default body. | 289 /// content-type information when creating a 500 response with a default body. |
| 290 Map<String, String> _adjustErrorHeaders(Map<String, String> headers) { | 290 Map<String, String> _adjustErrorHeaders(Map<String, String> headers) { |
| 291 if (headers == null || headers['content-type'] == null) { | 291 if (headers == null || headers['content-type'] == null) { |
| 292 return _addHeader(headers, 'content-type', 'text/plain'); | 292 return _addHeader(headers, 'content-type', 'text/plain'); |
| 293 } | 293 } |
| 294 | 294 |
| 295 var contentType = new MediaType.parse(headers['content-type']) | 295 var contentType = new MediaType.parse(headers['content-type']) |
| 296 .change(mimeType: 'text/plain'); | 296 .change(mimeType: 'text/plain'); |
| 297 return _addHeader(headers, 'content-type', contentType.toString()); | 297 return _addHeader(headers, 'content-type', contentType.toString()); |
| 298 } | 298 } |
| 299 | 299 |
| 300 /// Converts [location], which may be a [String] or a [Uri], to a [String]. | 300 /// Converts [location], which may be a [String] or a [Uri], to a [String]. |
| 301 /// | 301 /// |
| 302 /// Throws an [ArgumentError] if [location] isn't a [String] or a [Uri]. | 302 /// Throws an [ArgumentError] if [location] isn't a [String] or a [Uri]. |
| 303 String _locationToString(location) { | 303 String _locationToString(location) { |
| 304 if (location is String) return location; | 304 if (location is String) return location; |
| 305 if (location is Uri) return location.toString(); | 305 if (location is Uri) return location.toString(); |
| 306 | 306 |
| 307 throw new ArgumentError('Response location must be a String or Uri, was ' | 307 throw new ArgumentError('Response location must be a String or Uri, was ' |
| 308 '"$location".'); | 308 '"$location".'); |
| 309 } | 309 } |
| OLD | NEW |