Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Unified Diff: tests/standalone/io/http_connection_info_test.dart

Issue 10803033: Add the ability to get info of a Http connection, e.g. host and port. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Simplify wrapper function and fix a type. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/http_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/http_connection_info_test.dart
diff --git a/tests/standalone/io/http_connection_info_test.dart b/tests/standalone/io/http_connection_info_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..0583d608fb45f887e8371915cdbac50d2ed0b61e
--- /dev/null
+++ b/tests/standalone/io/http_connection_info_test.dart
@@ -0,0 +1,46 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#import("dart:io");
+
+void testHttpConnectionInfo() {
+ HttpServer server = new HttpServer();
+ server.listen("0.0.0.0", 0);
+ int clientPort;
+ server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {
+ Expect.isTrue(request.connectionInfo.remoteHost is String);
+ Expect.equals(request.connectionInfo.localPort, server.port);
+ Expect.isNotNull(clientPort);
+ Expect.equals(request.connectionInfo.remotePort, clientPort);
+ request.inputStream.onClosed = () {
+ response.outputStream.close();
+ };
+ };
+ server.onError = (Exception e) {
+ Expect.fail("Unexpected error: $e");
+ };
+
+
+ HttpClient client = new HttpClient();
+ HttpClientConnection conn = client.get("127.0.0.1", server.port, "/");
+ conn.onRequest = (HttpClientRequest request) {
+ Expect.isTrue(conn.connectionInfo.remoteHost is String);
+ Expect.equals(conn.connectionInfo.remotePort, server.port);
+ clientPort = conn.connectionInfo.localPort;
+ request.outputStream.close();
+ };
+ conn.onResponse = (HttpClientResponse response) {
+ response.inputStream.onClosed = () {
+ client.shutdown();
+ server.close();
+ };
+ };
+ conn.onError = (Exception e) {
+ Expect.fail("Unexpected error: $e");
+ };
+}
+
+void main() {
+ testHttpConnectionInfo();
+}
« no previous file with comments | « runtime/bin/http_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698