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

Unified Diff: tests/standalone/io/http_content_length_test.dart

Issue 11645044: Refactor handling of Transfer-Encoding (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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 | « sdk/lib/io/http_parser.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/http_content_length_test.dart
diff --git a/tests/standalone/io/http_content_length_test.dart b/tests/standalone/io/http_content_length_test.dart
index dfde31f73103b4edfebc23b525d285844af21011..1adc6869679597219a2d299d186af14577a3f71d 100644
--- a/tests/standalone/io/http_content_length_test.dart
+++ b/tests/standalone/io/http_content_length_test.dart
@@ -102,6 +102,66 @@ void testBody(int totalConnections, bool useHeader) {
}
}
+void testBodyChunked(int totalConnections, bool useHeader) {
+ HttpServer server = new HttpServer();
+ server.onError = (e) => Expect.fail("Unexpected error $e");
+ server.listen("127.0.0.1", 0, backlog: totalConnections);
+ server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {
+ Expect.isNull(request.headers.value('content-length'));
+ Expect.equals(-1, request.contentLength);
+ if (useHeader) {
+ response.contentLength = 2;
+ response.headers.chunkedTransferEncoding = true;
+ } else {
+ response.headers.set("content-length", 2);
+ response.headers.set("transfer-encoding", "chunked");
+ }
+ OutputStream stream = response.outputStream;
+ stream.writeString("x");
+ Expect.throws(() => response.headers.chunkedTransferEncoding = false,
+ (e) => e is HttpException);
+ stream.writeString("x");
+ stream.writeString("x");
+ stream.close();
+ Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
+ };
+
+ int count = 0;
+ HttpClient client = new HttpClient();
+ for (int i = 0; i < totalConnections; i++) {
+ HttpClientConnection conn = client.get("127.0.0.1", server.port, "/");
+ conn.onError = (e) => Expect.fail("Unexpected error $e");
+ conn.onRequest = (HttpClientRequest request) {
+ if (useHeader) {
+ request.contentLength = 2;
+ request.headers.chunkedTransferEncoding = true;
+ } else {
+ request.headers.add(HttpHeaders.CONTENT_LENGTH, "2");
+ request.headers.set(HttpHeaders.TRANSFER_ENCODING, "chunked");
+ }
+ OutputStream stream = request.outputStream;
+ stream.writeString("x");
+ Expect.throws(() => request.headers.chunkedTransferEncoding = false,
+ (e) => e is HttpException);
+ stream.writeString("x");
+ stream.writeString("x");
+ stream.close();
+ Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
+ };
+ conn.onResponse = (HttpClientResponse response) {
+ Expect.isNull(response.headers.value('content-length'));
+ Expect.equals(-1, response.contentLength);
+ response.inputStream.onData = response.inputStream.read;
+ response.inputStream.onClosed = () {
+ if (++count == totalConnections) {
+ client.shutdown();
+ server.close();
+ }
+ };
+ };
+ }
+}
+
void testHttp10() {
HttpServer server = new HttpServer();
server.onError = (e) => Expect.fail("Unexpected error $e");
@@ -133,5 +193,7 @@ void main() {
testNoBody(5, true);
testBody(5, false);
testBody(5, true);
+ testBodyChunked(5, false);
+ testBodyChunked(5, true);
testHttp10();
}
« no previous file with comments | « sdk/lib/io/http_parser.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698