Index: tests/standalone/io/http_10_test.dart |
diff --git a/tests/standalone/io/http_10_test.dart b/tests/standalone/io/http_10_test.dart |
index 3826a5efb50552811da76677507fef144a9c4bf2..0663a138c84a8495040eb97ed4841e163d972d08 100644 |
--- a/tests/standalone/io/http_10_test.dart |
+++ b/tests/standalone/io/http_10_test.dart |
@@ -17,74 +17,68 @@ import "dart:io"; |
// connection as there is no keep alive. |
void testHttp10NoKeepAlive() { |
HttpServer.bind("127.0.0.1", 0).then((server) { |
- server.listen( |
- (HttpRequest request) { |
- Expect.isNull(request.headers.value('content-length')); |
- Expect.equals(-1, request.contentLength); |
- var response = request.response; |
- response.contentLength = 1; |
- Expect.equals("1.0", request.protocolVersion); |
- response.done |
- .then((_) => Expect.fail("Unexpected response completion")) |
- .catchError((error) => Expect.isTrue(error is HttpException)); |
- response.write("Z"); |
- response.write("Z"); |
- response.close(); |
- response.write("x"); |
- }, |
- onError: (e, trace) { |
- String msg = "Unexpected error $e"; |
- if (trace != null) msg += "\nStackTrace: $trace"; |
- Expect.fail(msg); |
- }); |
+ server.listen((HttpRequest request) { |
+ Expect.isNull(request.headers.value('content-length')); |
+ Expect.equals(-1, request.contentLength); |
+ var response = request.response; |
+ response.contentLength = 1; |
+ Expect.equals("1.0", request.protocolVersion); |
+ response.done |
+ .then((_) => Expect.fail("Unexpected response completion")) |
+ .catchError((error) => Expect.isTrue(error is HttpException)); |
+ response.write("Z"); |
+ response.write("Z"); |
+ response.close(); |
+ response.write("x"); |
+ }, onError: (e, trace) { |
+ String msg = "Unexpected error $e"; |
+ if (trace != null) msg += "\nStackTrace: $trace"; |
+ Expect.fail(msg); |
+ }); |
int count = 0; |
makeRequest() { |
Socket.connect("127.0.0.1", server.port).then((socket) { |
- socket.write("GET / HTTP/1.0\r\n\r\n"); |
- |
- List<int> response = []; |
- socket.listen( |
- response.addAll, |
- onDone: () { |
- count++; |
- socket.destroy(); |
- String s = new String.fromCharCodes(response).toLowerCase(); |
- Expect.equals(-1, s.indexOf("keep-alive")); |
- if (count < 10) { |
- makeRequest(); |
- } else { |
- server.close(); |
- } |
- }); |
+ socket.write("GET / HTTP/1.0\r\n\r\n"); |
+ |
+ List<int> response = []; |
+ socket.listen(response.addAll, onDone: () { |
+ count++; |
+ socket.destroy(); |
+ String s = new String.fromCharCodes(response).toLowerCase(); |
+ Expect.equals(-1, s.indexOf("keep-alive")); |
+ if (count < 10) { |
+ makeRequest(); |
+ } else { |
+ server.close(); |
+ } |
}); |
+ }); |
} |
+ |
makeRequest(); |
}); |
} |
- |
// Client makes a HTTP 1.0 request and the server does not set a |
// content length so it has to close the connection to mark the end of |
// the response. |
void testHttp10ServerClose() { |
HttpServer.bind("127.0.0.1", 0).then((server) { |
- server.listen( |
- (HttpRequest request) { |
- Expect.isNull(request.headers.value('content-length')); |
- Expect.equals(-1, request.contentLength); |
- request.listen((_) {}, onDone: () { |
- var response = request.response; |
- Expect.equals("1.0", request.protocolVersion); |
- response.write("Z"); |
- response.close(); |
- }); |
- }, |
- onError: (e, trace) { |
- String msg = "Unexpected error $e"; |
- if (trace != null) msg += "\nStackTrace: $trace"; |
- Expect.fail(msg); |
- }); |
+ server.listen((HttpRequest request) { |
+ Expect.isNull(request.headers.value('content-length')); |
+ Expect.equals(-1, request.contentLength); |
+ request.listen((_) {}, onDone: () { |
+ var response = request.response; |
+ Expect.equals("1.0", request.protocolVersion); |
+ response.write("Z"); |
+ response.close(); |
+ }); |
+ }, onError: (e, trace) { |
+ String msg = "Unexpected error $e"; |
+ if (trace != null) msg += "\nStackTrace: $trace"; |
+ Expect.fail(msg); |
+ }); |
int count = 0; |
makeRequest() { |
@@ -93,8 +87,7 @@ void testHttp10ServerClose() { |
socket.write("Connection: Keep-Alive\r\n\r\n"); |
List<int> response = []; |
- socket.listen( |
- response.addAll, |
+ socket.listen(response.addAll, |
onDone: () { |
socket.destroy(); |
count++; |
@@ -111,32 +104,30 @@ void testHttp10ServerClose() { |
onError: (e) => print(e)); |
}); |
} |
+ |
makeRequest(); |
}); |
} |
- |
// Client makes a HTTP 1.0 request with connection keep alive. The |
// server sets a content length so the persistent connection can be |
// used. |
void testHttp10KeepAlive() { |
HttpServer.bind("127.0.0.1", 0).then((server) { |
- server.listen( |
- (HttpRequest request) { |
- Expect.isNull(request.headers.value('content-length')); |
- Expect.equals(-1, request.contentLength); |
- var response = request.response; |
- response.contentLength = 1; |
- response.persistentConnection = true; |
- Expect.equals("1.0", request.protocolVersion); |
- response.write("Z"); |
- response.close(); |
- }, |
- onError: (e, trace) { |
- String msg = "Unexpected error $e"; |
- if (trace != null) msg += "\nStackTrace: $trace"; |
- Expect.fail(msg); |
- }); |
+ server.listen((HttpRequest request) { |
+ Expect.isNull(request.headers.value('content-length')); |
+ Expect.equals(-1, request.contentLength); |
+ var response = request.response; |
+ response.contentLength = 1; |
+ response.persistentConnection = true; |
+ Expect.equals("1.0", request.protocolVersion); |
+ response.write("Z"); |
+ response.close(); |
+ }, onError: (e, trace) { |
+ String msg = "Unexpected error $e"; |
+ if (trace != null) msg += "\nStackTrace: $trace"; |
+ Expect.fail(msg); |
+ }); |
Socket.connect("127.0.0.1", server.port).then((socket) { |
void sendRequest() { |
@@ -146,51 +137,46 @@ void testHttp10KeepAlive() { |
List<int> response = []; |
int count = 0; |
- socket.listen( |
- (d) { |
- response.addAll(d); |
- if (response[response.length - 1] == "Z".codeUnitAt(0)) { |
- String s = new String.fromCharCodes(response).toLowerCase(); |
- Expect.isTrue(s.indexOf("\r\nconnection: keep-alive\r\n") > 0); |
- Expect.isTrue(s.indexOf("\r\ncontent-length: 1\r\n") > 0); |
- count++; |
- if (count < 10) { |
- response = []; |
- sendRequest(); |
- } else { |
- socket.close(); |
- } |
- } |
- }, |
- onDone: () { |
- socket.destroy(); |
- server.close(); |
- }); |
+ socket.listen((d) { |
+ response.addAll(d); |
+ if (response[response.length - 1] == "Z".codeUnitAt(0)) { |
+ String s = new String.fromCharCodes(response).toLowerCase(); |
+ Expect.isTrue(s.indexOf("\r\nconnection: keep-alive\r\n") > 0); |
+ Expect.isTrue(s.indexOf("\r\ncontent-length: 1\r\n") > 0); |
+ count++; |
+ if (count < 10) { |
+ response = []; |
+ sendRequest(); |
+ } else { |
+ socket.close(); |
+ } |
+ } |
+ }, onDone: () { |
+ socket.destroy(); |
+ server.close(); |
+ }); |
sendRequest(); |
}); |
}); |
} |
- |
// Client makes a HTTP 1.0 request with connection keep alive. The |
// server does not set a content length so it cannot honor connection |
// keep alive. |
void testHttp10KeepAliveServerCloses() { |
HttpServer.bind("127.0.0.1", 0).then((server) { |
- server.listen( |
- (HttpRequest request) { |
- Expect.isNull(request.headers.value('content-length')); |
- Expect.equals(-1, request.contentLength); |
- var response = request.response; |
- Expect.equals("1.0", request.protocolVersion); |
- response.write("Z"); |
- response.close(); |
- }, |
- onError: (e, trace) { |
- String msg = "Unexpected error $e"; |
- if (trace != null) msg += "\nStackTrace: $trace"; |
- Expect.fail(msg); |
- }); |
+ server.listen((HttpRequest request) { |
+ Expect.isNull(request.headers.value('content-length')); |
+ Expect.equals(-1, request.contentLength); |
+ var response = request.response; |
+ Expect.equals("1.0", request.protocolVersion); |
+ response.write("Z"); |
+ response.close(); |
+ }, onError: (e, trace) { |
+ String msg = "Unexpected error $e"; |
+ if (trace != null) msg += "\nStackTrace: $trace"; |
+ Expect.fail(msg); |
+ }); |
int count = 0; |
makeRequest() { |
@@ -199,28 +185,26 @@ void testHttp10KeepAliveServerCloses() { |
socket.write("Connection: Keep-Alive\r\n\r\n"); |
List<int> response = []; |
- socket.listen( |
- response.addAll, |
- onDone: () { |
- socket.destroy(); |
- count++; |
- String s = new String.fromCharCodes(response).toLowerCase(); |
- Expect.equals("z", s[s.length - 1]); |
- Expect.equals(-1, s.indexOf("content-length")); |
- Expect.equals(-1, s.indexOf("connection")); |
- if (count < 10) { |
- makeRequest(); |
- } else { |
- server.close(); |
- } |
- }); |
+ socket.listen(response.addAll, onDone: () { |
+ socket.destroy(); |
+ count++; |
+ String s = new String.fromCharCodes(response).toLowerCase(); |
+ Expect.equals("z", s[s.length - 1]); |
+ Expect.equals(-1, s.indexOf("content-length")); |
+ Expect.equals(-1, s.indexOf("connection")); |
+ if (count < 10) { |
+ makeRequest(); |
+ } else { |
+ server.close(); |
+ } |
}); |
+ }); |
} |
+ |
makeRequest(); |
}); |
} |
- |
void main() { |
testHttp10NoKeepAlive(); |
testHttp10ServerClose(); |