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

Side by Side Diff: tools/testing/dart/http_server.dart

Issue 12465018: Expanding WebSocket test (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 | « tests/html/websocket_test.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
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 library http_server; 5 library http_server;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:crypto';
Emily Fortuna 2013/03/18 22:44:22 I don't see where this import is used.
blois 2013/03/18 23:04:48 Remnant from before I noticed the WebSocketTransfo
8 import 'dart:io'; 9 import 'dart:io';
9 import 'dart:isolate'; 10 import 'dart:isolate';
10 import 'dart:uri'; 11 import 'dart:uri';
11 import 'test_suite.dart'; // For TestUtils. 12 import 'test_suite.dart'; // For TestUtils.
12 // TODO(efortuna): Rewrite to not use the args library and simply take an 13 // TODO(efortuna): Rewrite to not use the args library and simply take an
13 // expected number of arguments, so test.dart doesn't rely on the args library? 14 // expected number of arguments, so test.dart doesn't rely on the args library?
14 // See discussion on https://codereview.chromium.org/11931025/. 15 // See discussion on https://codereview.chromium.org/11931025/.
15 import 'vendored_pkg/args/args.dart'; 16 import 'vendored_pkg/args/args.dart';
16 import 'utils.dart'; 17 import 'utils.dart';
17 18
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 for (var server in _serverList) { 126 for (var server in _serverList) {
126 server.close(); 127 server.close();
127 } 128 }
128 } 129 }
129 130
130 Future _startHttpServer(String host, {int port: 0, int allowedPort: -1}) { 131 Future _startHttpServer(String host, {int port: 0, int allowedPort: -1}) {
131 return HttpServer.bind(host, port).then((HttpServer httpServer) { 132 return HttpServer.bind(host, port).then((HttpServer httpServer) {
132 httpServer.listen((HttpRequest request) { 133 httpServer.listen((HttpRequest request) {
133 if (request.uri.path == "/echo") { 134 if (request.uri.path == "/echo") {
134 _handleEchoRequest(request, request.response); 135 _handleEchoRequest(request, request.response);
136 } else if (request.uri.path == '/ws') {
137 _handleWebSocketRequest(request);
135 } else { 138 } else {
136 _handleFileOrDirectoryRequest( 139 _handleFileOrDirectoryRequest(
137 request, request.response, allowedPort); 140 request, request.response, allowedPort);
138 } 141 }
139 }, 142 },
140 onError: (e) { 143 onError: (e) {
141 DebugLogger.error('HttpServer: an error occured: $e'); 144 DebugLogger.error('HttpServer: an error occured: $e');
142 }); 145 });
143 _serverList.add(httpServer); 146 _serverList.add(httpServer);
144 }); 147 });
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 182 }
180 183
181 void _handleEchoRequest(HttpRequest request, HttpResponse response) { 184 void _handleEchoRequest(HttpRequest request, HttpResponse response) {
182 response.headers.set("Access-Control-Allow-Origin", "*"); 185 response.headers.set("Access-Control-Allow-Origin", "*");
183 request.pipe(response).catchError((e) { 186 request.pipe(response).catchError((e) {
184 DebugLogger.warning( 187 DebugLogger.warning(
185 'HttpServer: error while closing the response stream: $e'); 188 'HttpServer: error while closing the response stream: $e');
186 }); 189 });
187 } 190 }
188 191
192 void _handleWebSocketRequest(HttpRequest request) {
193 WebSocketTransformer.upgrade(request).then((websocket) {
194 websocket.listen((data) {
195 websocket.send(data);
196 websocket.close();
197 });
198 });
199 }
200
189 Path _getFilePathFromRequestPath(String urlRequestPath) { 201 Path _getFilePathFromRequestPath(String urlRequestPath) {
190 // Go to the top of the file to see an explanation of the URL path scheme. 202 // Go to the top of the file to see an explanation of the URL path scheme.
191 var requestPath = new Path(urlRequestPath.substring(1)).canonicalize(); 203 var requestPath = new Path(urlRequestPath.substring(1)).canonicalize();
192 var pathSegments = requestPath.segments(); 204 var pathSegments = requestPath.segments();
193 if (pathSegments.length > 0) { 205 if (pathSegments.length > 0) {
194 var basePath; 206 var basePath;
195 var relativePath; 207 var relativePath;
196 if (pathSegments[0] == PREFIX_BUILDDIR) { 208 if (pathSegments[0] == PREFIX_BUILDDIR) {
197 basePath = _buildDirectory; 209 basePath = _buildDirectory;
198 relativePath = new Path( 210 relativePath = new Path(
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 class _Entry { 354 class _Entry {
343 final String name; 355 final String name;
344 final String displayName; 356 final String displayName;
345 357
346 _Entry(this.name, this.displayName); 358 _Entry(this.name, this.displayName);
347 359
348 int compareTo(_Entry other) { 360 int compareTo(_Entry other) {
349 return name.compareTo(other.name); 361 return name.compareTo(other.name);
350 } 362 }
351 } 363 }
OLDNEW
« no previous file with comments | « tests/html/websocket_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698