| 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 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 import "package:unittest/unittest.dart"; | 8 import "package:unittest/unittest.dart"; |
| 9 import "package:http_server/http_server.dart"; | 9 import "package:http_server/http_server.dart"; |
| 10 | 10 |
| 11 | 11 import 'utils.dart'; |
| 12 Future<int> getStatusCode(int port, | |
| 13 String path, | |
| 14 {DateTime ifModifiedSince}) { | |
| 15 return new HttpClient().get('localhost', port, path) | |
| 16 .then((request) { | |
| 17 if (ifModifiedSince != null) { | |
| 18 request.headers.ifModifiedSince = ifModifiedSince; | |
| 19 } | |
| 20 return request.close(); | |
| 21 }) | |
| 22 .then((response) => response.drain().then( | |
| 23 (_) => response.statusCode)); | |
| 24 } | |
| 25 | |
| 26 Future<HttpHeaders> getHeaders(int port, String path) { | |
| 27 return new HttpClient().get('localhost', port, path) | |
| 28 .then((request) => request.close()) | |
| 29 .then((response) => response.drain().then( | |
| 30 (_) => response.headers)); | |
| 31 } | |
| 32 | 12 |
| 33 | 13 |
| 34 void main() { | 14 void main() { |
| 35 group('serve-root', () { | 15 group('serve-root', () { |
| 36 test('dir-exists', () { | 16 test('dir-exists', () { |
| 37 expect(HttpServer.bind('localhost', 0).then((server) { | 17 expect(HttpServer.bind('localhost', 0).then((server) { |
| 38 var dir = new Directory('').createTempSync(); | 18 var dir = new Directory('').createTempSync(); |
| 39 var virDir = new VirtualDirectory(dir.path); | 19 var virDir = new VirtualDirectory(dir.path); |
| 40 | 20 |
| 41 virDir.serve(server); | 21 virDir.serve(server); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 .whenComplete(() { | 281 .whenComplete(() { |
| 302 server.close(); | 282 server.close(); |
| 303 dir.deleteSync(recursive: true); | 283 dir.deleteSync(recursive: true); |
| 304 }); | 284 }); |
| 305 }), completion(equals(HttpStatus.OK))); | 285 }), completion(equals(HttpStatus.OK))); |
| 306 }); | 286 }); |
| 307 }); | 287 }); |
| 308 }); | 288 }); |
| 309 } | 289 } |
| 310 | 290 |
| OLD | NEW |