Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import "dart:isolate"; | 5 import "dart:isolate"; |
| 6 import "dart:io"; | 6 import "dart:io"; |
| 7 | 7 |
| 8 void testNoBody(int totalConnections, bool explicitContentLength) { | 8 void testNoBody(int totalConnections, bool explicitContentLength) { |
| 9 HttpServer server = new HttpServer(); | 9 HttpServer server = new HttpServer(); |
| 10 server.onError = (e) => Expect.fail("Unexpected error $e"); | 10 server.onError = (e) => Expect.fail("Unexpected error $e"); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 server.onError = (e) => Expect.fail("Unexpected error $e"); | 52 server.onError = (e) => Expect.fail("Unexpected error $e"); |
| 53 server.listen("127.0.0.1", 0, backlog: totalConnections); | 53 server.listen("127.0.0.1", 0, backlog: totalConnections); |
| 54 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { | 54 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { |
| 55 Expect.equals("2", request.headers.value('content-length')); | 55 Expect.equals("2", request.headers.value('content-length')); |
| 56 Expect.equals(2, request.contentLength); | 56 Expect.equals(2, request.contentLength); |
| 57 if (useHeader) { | 57 if (useHeader) { |
| 58 response.contentLength = 2; | 58 response.contentLength = 2; |
| 59 } else { | 59 } else { |
| 60 response.headers.set("content-length", 2); | 60 response.headers.set("content-length", 2); |
| 61 } | 61 } |
| 62 OutputStream stream = response.outputStream; | 62 request.inputStream.onData = request.inputStream.read; |
| 63 stream.writeString("x"); | 63 request.inputStream.onClosed = () { |
| 64 Expect.throws(() => response.contentLength = 3, (e) => e is HttpException); | 64 OutputStream stream = response.outputStream; |
| 65 stream.writeString("x"); | 65 stream.writeString("x"); |
| 66 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); | 66 Expect.throws(() => response.contentLength = 3, (e) => e is HttpException) ; |
|
Mads Ager (google)
2013/01/02 13:26:43
Long line.
| |
| 67 stream.close(); | 67 stream.writeString("x"); |
| 68 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); | 68 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); |
| 69 stream.close(); | |
| 70 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); | |
| 71 }; | |
| 69 }; | 72 }; |
| 70 | 73 |
| 71 int count = 0; | 74 int count = 0; |
| 72 HttpClient client = new HttpClient(); | 75 HttpClient client = new HttpClient(); |
| 73 for (int i = 0; i < totalConnections; i++) { | 76 for (int i = 0; i < totalConnections; i++) { |
| 74 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/"); | 77 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/"); |
| 75 conn.onError = (e) => Expect.fail("Unexpected error $e"); | 78 conn.onError = (e) => Expect.fail("Unexpected error $e"); |
| 76 conn.onRequest = (HttpClientRequest request) { | 79 conn.onRequest = (HttpClientRequest request) { |
| 77 if (useHeader) { | 80 if (useHeader) { |
| 78 request.contentLength = 2; | 81 request.contentLength = 2; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 109 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { | 112 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { |
| 110 Expect.isNull(request.headers.value('content-length')); | 113 Expect.isNull(request.headers.value('content-length')); |
| 111 Expect.equals(-1, request.contentLength); | 114 Expect.equals(-1, request.contentLength); |
| 112 if (useHeader) { | 115 if (useHeader) { |
| 113 response.contentLength = 2; | 116 response.contentLength = 2; |
| 114 response.headers.chunkedTransferEncoding = true; | 117 response.headers.chunkedTransferEncoding = true; |
| 115 } else { | 118 } else { |
| 116 response.headers.set("content-length", 2); | 119 response.headers.set("content-length", 2); |
| 117 response.headers.set("transfer-encoding", "chunked"); | 120 response.headers.set("transfer-encoding", "chunked"); |
| 118 } | 121 } |
| 119 OutputStream stream = response.outputStream; | 122 request.inputStream.onData = request.inputStream.read; |
| 120 stream.writeString("x"); | 123 request.inputStream.onClosed = () { |
| 121 Expect.throws(() => response.headers.chunkedTransferEncoding = false, | 124 OutputStream stream = response.outputStream; |
| 122 (e) => e is HttpException); | 125 stream.writeString("x"); |
| 123 stream.writeString("x"); | 126 Expect.throws(() => response.headers.chunkedTransferEncoding = false, |
| 124 stream.writeString("x"); | 127 (e) => e is HttpException); |
| 125 stream.close(); | 128 stream.writeString("x"); |
| 126 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); | 129 stream.writeString("x"); |
| 130 stream.close(); | |
| 131 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); | |
| 132 }; | |
| 127 }; | 133 }; |
| 128 | 134 |
| 129 int count = 0; | 135 int count = 0; |
| 130 HttpClient client = new HttpClient(); | 136 HttpClient client = new HttpClient(); |
| 131 for (int i = 0; i < totalConnections; i++) { | 137 for (int i = 0; i < totalConnections; i++) { |
| 132 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/"); | 138 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/"); |
| 133 conn.onError = (e) => Expect.fail("Unexpected error $e"); | 139 conn.onError = (e) => Expect.fail("Unexpected error $e"); |
| 134 conn.onRequest = (HttpClientRequest request) { | 140 conn.onRequest = (HttpClientRequest request) { |
| 135 if (useHeader) { | 141 if (useHeader) { |
| 136 request.contentLength = 2; | 142 request.contentLength = 2; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 server.close(); | 192 server.close(); |
| 187 }; | 193 }; |
| 188 }; | 194 }; |
| 189 } | 195 } |
| 190 | 196 |
| 191 void main() { | 197 void main() { |
| 192 testNoBody(5, false); | 198 testNoBody(5, false); |
| 193 testNoBody(5, true); | 199 testNoBody(5, true); |
| 194 testBody(5, false); | 200 testBody(5, false); |
| 195 testBody(5, true); | 201 testBody(5, true); |
| 196 // These tests can fail or timeout on Windows, issue 7562. | 202 testBodyChunked(5, false); |
| 197 if (Platform.operatingSystem != 'windows') { | 203 testBodyChunked(5, true); |
| 198 testBodyChunked(5, false); | |
| 199 testBodyChunked(5, true); | |
| 200 } | |
| 201 testHttp10(); | 204 testHttp10(); |
| 202 } | 205 } |
| OLD | NEW |