| 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.cascade; | 5 library shelf.cascade; |
| 6 | 6 |
| 7 import 'handler.dart'; | 7 import 'handler.dart'; |
| 8 import 'response.dart'; | 8 import 'response.dart'; |
| 9 import 'util.dart'; | 9 import 'util.dart'; |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 /// the next handler. | 31 /// the next handler. |
| 32 final _ShouldCascade _shouldCascade; | 32 final _ShouldCascade _shouldCascade; |
| 33 | 33 |
| 34 final Cascade _parent; | 34 final Cascade _parent; |
| 35 final Handler _handler; | 35 final Handler _handler; |
| 36 | 36 |
| 37 /// Creates a new, empty cascade. | 37 /// Creates a new, empty cascade. |
| 38 /// | 38 /// |
| 39 /// If [statusCodes] is passed, responses with those status codes are | 39 /// If [statusCodes] is passed, responses with those status codes are |
| 40 /// considered unacceptable. If [shouldCascade] is passed, responses for which | 40 /// considered unacceptable. If [shouldCascade] is passed, responses for which |
| 41 /// it returns `true` are considered unacceptale. [statusCode] and | 41 /// it returns `true` are considered unacceptable. [statusCode] and |
| 42 /// [shouldCascade] may not both be passed. | 42 /// [shouldCascade] may not both be passed. |
| 43 Cascade({Iterable<int> statusCodes, bool shouldCascade(Response response)}) | 43 Cascade({Iterable<int> statusCodes, bool shouldCascade(Response response)}) |
| 44 : _shouldCascade = _computeShouldCascade(statusCodes, shouldCascade), | 44 : _shouldCascade = _computeShouldCascade(statusCodes, shouldCascade), |
| 45 _parent = null, | 45 _parent = null, |
| 46 _handler = null { | 46 _handler = null { |
| 47 if (statusCodes != null && shouldCascade != null) { | 47 if (statusCodes != null && shouldCascade != null) { |
| 48 throw new ArgumentError("statusCodes and shouldCascade may not both be " | 48 throw new ArgumentError("statusCodes and shouldCascade may not both be " |
| 49 "passed."); | 49 "passed."); |
| 50 } | 50 } |
| 51 } | 51 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 81 | 81 |
| 82 /// Computes the [Cascade._shouldCascade] function based on the user's | 82 /// Computes the [Cascade._shouldCascade] function based on the user's |
| 83 /// parameters. | 83 /// parameters. |
| 84 Function _computeShouldCascade( | 84 Function _computeShouldCascade( |
| 85 Iterable<int> statusCodes, Function shouldCascade) { | 85 Iterable<int> statusCodes, Function shouldCascade) { |
| 86 if (shouldCascade != null) return shouldCascade; | 86 if (shouldCascade != null) return shouldCascade; |
| 87 if (statusCodes == null) statusCodes = [404, 405]; | 87 if (statusCodes == null) statusCodes = [404, 405]; |
| 88 statusCodes = statusCodes.toSet(); | 88 statusCodes = statusCodes.toSet(); |
| 89 return (response) => statusCodes.contains(response.statusCode); | 89 return (response) => statusCodes.contains(response.statusCode); |
| 90 } | 90 } |
| OLD | NEW |