| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 // | |
| 5 | |
| 6 import "dart:io"; | |
| 7 import "dart:uri"; | |
| 8 | |
| 9 main() { | |
| 10 bool serverOnClosed = false; | |
| 11 bool clientOnClosed = false; | |
| 12 | |
| 13 var server = new HttpServer(); | |
| 14 server.listen("127.0.0.1", 0); | |
| 15 server.defaultRequestHandler = (request, response) { | |
| 16 request.inputStream.onData = request.inputStream.read; | |
| 17 request.inputStream.onClosed = () { | |
| 18 response.outputStream.onClosed = () => serverOnClosed = true; | |
| 19 response.outputStream.writeString("hello!"); | |
| 20 response.outputStream.close(); | |
| 21 }; | |
| 22 }; | |
| 23 | |
| 24 var client = new HttpClient(); | |
| 25 var connection = client.postUrl(new Uri.fromString("http://127.0.0.1:${serve
r.port}")); | |
| 26 connection.onError = (e) => throw e; | |
| 27 connection.onRequest = (request) { | |
| 28 request.contentLength = "hello!".length; | |
| 29 request.outputStream.onError = (e) => throw e; | |
| 30 request.outputStream.onClosed = () => clientOnClosed = true; | |
| 31 request.outputStream.writeString("hello!"); | |
| 32 request.outputStream.close(); | |
| 33 }; | |
| 34 connection.onResponse = (response) { | |
| 35 response.inputStream.onData = response.inputStream.read; | |
| 36 response.inputStream.onClosed = () { | |
| 37 Expect.isTrue(serverOnClosed && clientOnClosed); | |
| 38 server.close(); | |
| 39 client.shutdown(); | |
| 40 }; | |
| 41 }; | |
| 42 } | |
| OLD | NEW |