| 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import "dart:io"; | 6 import "dart:io"; |
| 7 | 7 |
| 8 void testHttpConnectionInfo() { | 8 void testHttpConnectionInfo() { |
| 9 HttpServer.bind("0.0.0.0", 0).then((server) { | 9 HttpServer.bind("0.0.0.0", 0).then((server) { |
| 10 int clientPort; | 10 int clientPort; |
| 11 | 11 |
| 12 server.listen((request) { | 12 server.listen((request) { |
| 13 var response = request.response; | 13 var response = request.response; |
| 14 Expect.isTrue(request.connectionInfo.remoteHost is String); | 14 Expect.isTrue(request.connectionInfo.remoteAddress is InternetAddress); |
| 15 Expect.isTrue(response.connectionInfo.remoteHost is String); | 15 Expect.isTrue(response.connectionInfo.remoteAddress is InternetAddress); |
| 16 Expect.equals(request.connectionInfo.localPort, server.port); | 16 Expect.equals(request.connectionInfo.localPort, server.port); |
| 17 Expect.equals(response.connectionInfo.localPort, server.port); | 17 Expect.equals(response.connectionInfo.localPort, server.port); |
| 18 Expect.isNotNull(clientPort); | 18 Expect.isNotNull(clientPort); |
| 19 Expect.equals(request.connectionInfo.remotePort, clientPort); | 19 Expect.equals(request.connectionInfo.remotePort, clientPort); |
| 20 Expect.equals(response.connectionInfo.remotePort, clientPort); | 20 Expect.equals(response.connectionInfo.remotePort, clientPort); |
| 21 request.listen( | 21 request.listen( |
| 22 (_) { }, | 22 (_) { }, |
| 23 onDone: () { request.response.close(); }); | 23 onDone: () { request.response.close(); }); |
| 24 }); | 24 }); |
| 25 | 25 |
| 26 HttpClient client = new HttpClient(); | 26 HttpClient client = new HttpClient(); |
| 27 client.get("127.0.0.1", server.port, "/") | 27 client.get("127.0.0.1", server.port, "/") |
| 28 .then((request) { | 28 .then((request) { |
| 29 Expect.isTrue(request.connectionInfo.remoteHost is String); | 29 Expect.isTrue( |
| 30 request.connectionInfo.remoteAddress is InternetAddress); |
| 30 Expect.equals(request.connectionInfo.remotePort, server.port); | 31 Expect.equals(request.connectionInfo.remotePort, server.port); |
| 31 clientPort = request.connectionInfo.localPort; | 32 clientPort = request.connectionInfo.localPort; |
| 32 return request.close(); | 33 return request.close(); |
| 33 }) | 34 }) |
| 34 .then((response) { | 35 .then((response) { |
| 35 Expect.equals(server.port, response.connectionInfo.remotePort); | 36 Expect.equals(server.port, response.connectionInfo.remotePort); |
| 36 Expect.equals(clientPort, response.connectionInfo.localPort); | 37 Expect.equals(clientPort, response.connectionInfo.localPort); |
| 37 response.listen( | 38 response.listen( |
| 38 (_) { }, | 39 (_) { }, |
| 39 onDone: () { | 40 onDone: () { |
| 40 client.close(); | 41 client.close(); |
| 41 server.close(); | 42 server.close(); |
| 42 }); | 43 }); |
| 43 }); | 44 }); |
| 44 }); | 45 }); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void main() { | 48 void main() { |
| 48 testHttpConnectionInfo(); | 49 testHttpConnectionInfo(); |
| 49 } | 50 } |
| OLD | NEW |