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 | 5 |
| 6 #import("dart:isolate"); | 6 #import("dart:isolate"); |
| 7 #import("dart:io"); | 7 #import("dart:io"); |
| 8 | 8 |
| 9 void testNoBody(int totalConnections) { | 9 void testNoBody(int totalConnections) { |
| 10 HttpServer server = new HttpServer(); | 10 HttpServer server = new HttpServer(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 conn.onResponse = (HttpClientResponse response) { | 72 conn.onResponse = (HttpClientResponse response) { |
| 73 count++; | 73 count++; |
| 74 if (count == totalConnections) { | 74 if (count == totalConnections) { |
| 75 client.shutdown(); | 75 client.shutdown(); |
| 76 server.close(); | 76 server.close(); |
| 77 } | 77 } |
| 78 }; | 78 }; |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 void testHttp10() { | |
| 83 HttpServer server = new HttpServer(); | |
| 84 server.onError = (e) => Expect.fail("Unexpected error $e"); | |
| 85 server.listen("127.0.0.1", 0, 5); | |
| 86 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { | |
| 87 OutputStream stream = response.outputStream; | |
| 88 Expect.equals("1.0", request.protocolVersion); | |
| 89 Expect.throws(() => stream.writeString("x"), (e) => e is HttpException); | |
| 90 response.contentLength = 0; | |
| 91 stream.close(); | |
| 92 }; | |
| 93 | |
| 94 Socket socket = new Socket("127.0.0.1", server.port); | |
| 95 socket.onConnect = () { | |
| 96 List<int> buffer = new List<int>(1024); | |
| 97 socket.outputStream.writeString("GET / HTTP/1.0\r\n\r\n"); | |
| 98 socket.onData = () => socket.readList(buffer, 0, buffer.length); | |
| 99 socket.onClosed = () { | |
|
Mads Ager (google)
2012/05/09 07:42:14
Indentation is off.
Søren Gjesse
2012/05/09 08:57:02
Done.
| |
| 100 socket.close(true); | |
| 101 server.close(); | |
| 102 }; | |
| 103 }; | |
| 104 } | |
| 105 | |
| 82 void main() { | 106 void main() { |
| 83 testNoBody(5); | 107 testNoBody(5); |
| 84 testBody(5); | 108 testBody(5); |
| 109 testHttp10(); | |
| 85 } | 110 } |
| OLD | NEW |