| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #import("dart:io"); |
| 6 |
| 7 void testHttpConnectionInfo() { |
| 8 HttpServer server = new HttpServer(); |
| 9 server.listen("0.0.0.0", 0); |
| 10 int clientPort; |
| 11 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { |
| 12 Expect.isTrue(request.connectionInfo.remoteHost is String); |
| 13 Expect.equals(request.connectionInfo.localPort, server.port); |
| 14 Expect.isNotNull(clientPort); |
| 15 Expect.equals(request.connectionInfo.remotePort, clientPort); |
| 16 request.inputStream.onClosed = () { |
| 17 response.outputStream.close(); |
| 18 }; |
| 19 }; |
| 20 server.onError = (Exception e) { |
| 21 Expect.fail("Unexpected error: $e"); |
| 22 }; |
| 23 |
| 24 |
| 25 HttpClient client = new HttpClient(); |
| 26 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/"); |
| 27 conn.onRequest = (HttpClientRequest request) { |
| 28 Expect.isTrue(conn.connectionInfo.remoteHost is String); |
| 29 Expect.equals(conn.connectionInfo.remotePort, server.port); |
| 30 clientPort = conn.connectionInfo.localPort; |
| 31 request.outputStream.close(); |
| 32 }; |
| 33 conn.onResponse = (HttpClientResponse response) { |
| 34 response.inputStream.onClosed = () { |
| 35 client.shutdown(); |
| 36 server.close(); |
| 37 }; |
| 38 }; |
| 39 conn.onError = (Exception e) { |
| 40 Expect.fail("Unexpected error: $e"); |
| 41 }; |
| 42 } |
| 43 |
| 44 void main() { |
| 45 testHttpConnectionInfo(); |
| 46 } |
| OLD | NEW |