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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/http_impl.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« 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