Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(969)

Unified Diff: pkg/shelf/test/shelf_io_test.dart

Issue 260933004: Support Request hijacking in Shelf, using a similar API to Rack. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/shelf/test/log_middleware_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/shelf/test/shelf_io_test.dart
diff --git a/pkg/shelf/test/shelf_io_test.dart b/pkg/shelf/test/shelf_io_test.dart
index bdece66973838198312f835b312828e4d00d1209..520565809d0b95a7b3baef7ea9d990daca3a6744 100644
--- a/pkg/shelf/test/shelf_io_test.dart
+++ b/pkg/shelf/test/shelf_io_test.dart
@@ -185,6 +185,39 @@ void main() {
});
});
+ test('supports request hijacking', () {
+ _scheduleServer((request) {
+ expect(request.method, 'POST');
+
+ request.hijack(expectAsync((stream, sink) {
+ expect(stream.first, completion(equals("Hello".codeUnits)));
+
+ sink.add((
+ "HTTP/1.1 404 Not Found\r\n"
+ "Date: Mon, 23 May 2005 22:38:34 GMT\r\n"
+ "Content-Length: 13\r\n"
+ "\r\n"
+ "Hello, world!").codeUnits);
+ sink.close();
+ }));
+ });
+
+ return _schedulePost(body: "Hello").then((response) {
+ expect(response.statusCode, HttpStatus.NOT_FOUND);
+ expect(response.headers["date"], "Mon, 23 May 2005 22:38:34 GMT");
+ expect(response.stream.bytesToString(),
+ completion(equals("Hello, world!")));
+ });
+ });
+
+ test('reports an error if a HijackException is thrown without hijacking', () {
+ _scheduleServer((request) => throw const HijackException());
+
+ return _scheduleGet().then((response) {
+ expect(response.statusCode, HttpStatus.INTERNAL_SERVER_ERROR);
+ });
+ });
+
test('passes asynchronous exceptions to the parent error zone', () {
return runZoned(() {
return shelf_io.serve((request) {
« no previous file with comments | « pkg/shelf/test/log_middleware_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698