OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 scheduled_test.scheduled_server; | 5 library scheduled_test.scheduled_server; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 | 10 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 81 } |
82 | 82 |
83 /// The handler for incoming [shelf.Request]s to this server. | 83 /// The handler for incoming [shelf.Request]s to this server. |
84 /// | 84 /// |
85 /// This dispatches the request to the first handler in the queue. It's that | 85 /// This dispatches the request to the first handler in the queue. It's that |
86 /// handler's responsibility to check that the method/path are correct and | 86 /// handler's responsibility to check that the method/path are correct and |
87 /// that it's being run at the correct time. | 87 /// that it's being run at the correct time. |
88 Future<shelf.Response> _handleRequest(shelf.Request request) { | 88 Future<shelf.Response> _handleRequest(shelf.Request request) { |
89 return wrapFuture(syncFuture(() { | 89 return wrapFuture(syncFuture(() { |
90 if (_handlers.isEmpty) { | 90 if (_handlers.isEmpty) { |
91 fail("'$description' received ${request.method} ${request.pathInfo} " | 91 fail("'$description' received ${request.method} ${request.url.path} " |
92 "when no more requests were expected."); | 92 "when no more requests were expected."); |
93 } | 93 } |
94 return _handlers.removeFirst().fn(request); | 94 return _handlers.removeFirst().fn(request); |
95 }), 'receiving ${request.method} ${request.pathInfo}').catchError((error) { | 95 }), 'receiving ${request.method} ${request.url.path}').catchError((error) { |
96 // Don't let errors bubble up to the shelf handler. It will print them to | 96 // Don't let errors bubble up to the shelf handler. It will print them to |
97 // stderr, but the user will already be notified via the scheduled_test | 97 // stderr, but the user will already be notified via the scheduled_test |
98 // infrastructure. | 98 // infrastructure. |
99 return new shelf.Response.internalServerError( | 99 return new shelf.Response.internalServerError( |
100 body: error.toString(), | 100 body: error.toString(), |
101 headers: {'content-type': 'text/plain'}); | 101 headers: {'content-type': 'text/plain'}); |
102 }); | 102 }); |
103 } | 103 } |
104 } | 104 } |
OLD | NEW |