| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 | 5 |
| 6 import "dart:isolate"; | 6 import "dart:isolate"; |
| 7 import "dart:io"; | 7 import "dart:io"; |
| 8 | 8 |
| 9 void test(int totalConnections, [String body]) { | 9 void test(int totalConnections, [String body]) { |
| 10 HttpServer.bind().then((server) { | 10 HttpServer.bind().then((server) { |
| 11 | 11 |
| 12 server.listen((HttpRequest request) { | 12 server.listen((HttpRequest request) { |
| 13 HttpResponse response = request.response; | 13 HttpResponse response = request.response; |
| 14 // Cannot mutate request headers. | 14 // Cannot mutate request headers. |
| 15 Expect.throws(() => request.headers.add("X-Request-Header", "value"), | 15 Expect.throws(() => request.headers.add("X-Request-Header", "value"), |
| 16 (e) => e is HttpException); | 16 (e) => e is HttpException); |
| 17 Expect.equals("value", request.headers.value("X-Request-Header")); | 17 Expect.equals("value", request.headers.value("X-Request-Header")); |
| 18 request.listen((_) {}, onDone: () { | 18 request.listen((_) {}, onDone: () { |
| 19 // Can still mutate response headers as long as no data has been sent. | 19 // Can still mutate response headers as long as no data has been sent. |
| 20 response.headers.add("X-Response-Header", "value"); | 20 response.headers.add("X-Response-Header", "value"); |
| 21 if (body != null) { | 21 if (body != null) { |
| 22 response.addString(body); | 22 response.write(body); |
| 23 // Cannot mutate response headers when data has been sent. | 23 // Cannot mutate response headers when data has been sent. |
| 24 Expect.throws(() => request.headers.add("X-Request-Header", "value2"), | 24 Expect.throws(() => request.headers.add("X-Request-Header", "value2"), |
| 25 (e) => e is HttpException); | 25 (e) => e is HttpException); |
| 26 } | 26 } |
| 27 response..close(); | 27 response..close(); |
| 28 // Cannot mutate response headers when data has been sent. | 28 // Cannot mutate response headers when data has been sent. |
| 29 Expect.throws(() => request.headers.add("X-Request-Header", "value3"), | 29 Expect.throws(() => request.headers.add("X-Request-Header", "value3"), |
| 30 (e) => e is HttpException); | 30 (e) => e is HttpException); |
| 31 }); | 31 }); |
| 32 }); | 32 }); |
| 33 | 33 |
| 34 int count = 0; | 34 int count = 0; |
| 35 HttpClient client = new HttpClient(); | 35 HttpClient client = new HttpClient(); |
| 36 for (int i = 0; i < totalConnections; i++) { | 36 for (int i = 0; i < totalConnections; i++) { |
| 37 client.get("127.0.0.1", server.port, "/") | 37 client.get("127.0.0.1", server.port, "/") |
| 38 .then((HttpClientRequest request) { | 38 .then((HttpClientRequest request) { |
| 39 if (body != null) { | 39 if (body != null) { |
| 40 request.contentLength = -1; | 40 request.contentLength = -1; |
| 41 } | 41 } |
| 42 // Can still mutate request headers as long as no data has been sent. | 42 // Can still mutate request headers as long as no data has been sent. |
| 43 request.headers.add("X-Request-Header", "value"); | 43 request.headers.add("X-Request-Header", "value"); |
| 44 if (body != null) { | 44 if (body != null) { |
| 45 request.addString(body); | 45 request.write(body); |
| 46 // Cannot mutate request headers when data has been sent. | 46 // Cannot mutate request headers when data has been sent. |
| 47 Expect.throws( | 47 Expect.throws( |
| 48 () => request.headers.add("X-Request-Header", "value2"), | 48 () => request.headers.add("X-Request-Header", "value2"), |
| 49 (e) => e is HttpException); | 49 (e) => e is HttpException); |
| 50 } | 50 } |
| 51 request.close(); | 51 request.close(); |
| 52 // Cannot mutate request headers when data has been sent. | 52 // Cannot mutate request headers when data has been sent. |
| 53 Expect.throws(() => request.headers.add("X-Request-Header", "value3"), | 53 Expect.throws(() => request.headers.add("X-Request-Header", "value3"), |
| 54 (e) => e is HttpException); | 54 (e) => e is HttpException); |
| 55 return request.response; | 55 return request.response; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 71 }); | 71 }); |
| 72 } | 72 } |
| 73 | 73 |
| 74 }); | 74 }); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void main() { | 77 void main() { |
| 78 test(5); | 78 test(5); |
| 79 test(5, "Hello and goodbye"); | 79 test(5, "Hello and goodbye"); |
| 80 } | 80 } |
| OLD | NEW |