Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/src/alfred.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,13 @@ class Alfred with Router {

// We track if the response has been resolved in order to exit out early
// the list of routes (ie the middleware returned)
_unawaited(request.response.done.then((dynamic _) {
var doneFuture = request.response.done.then((dynamic _) {
isDone = true;
for (var listener in _onDoneListeners) {
listener(request, request.response);
}
logWriter(() => 'Response sent to client', LogType.debug);
}));
});

/// Parse request to Method enum value.
Method _parseMethod(HttpRequest request) {
Expand Down Expand Up @@ -402,6 +402,9 @@ class Alfred with Router {
}
}
}

// Ensure done handlers are called before returning
await doneFuture;
}

/// Responds request with a NotFound response
Expand Down
17 changes: 10 additions & 7 deletions test/alfred_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -691,13 +691,16 @@ void main() {
await http.get(Uri.parse('http://localhost:$port/resource'));

bool inLog(String part) =>
logs.isNotEmpty && logs.where((log) => log.contains(part)).isNotEmpty;

expect(inLog('info GET - /resource'), true);
expect(inLog('debug Match route: /resource'), true);
expect(inLog('debug Apply middleware'), true);
expect(inLog('debug Apply TypeHandler for result type: String'), true);
expect(inLog('debug Response sent to client'), true);
logs.isNotEmpty &&
logs
.where((log) => log.toLowerCase().contains(part.toLowerCase()))
.isNotEmpty;

expect(inLog('get - /resource'), true);
expect(inLog('match route'), true);
expect(inLog('middleware'), true);
expect(inLog('typehandler'), true);
expect(inLog('response sent'), true);
});

test('it prints the routes without error', () {
Expand Down