| 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:http_server/http_server.dart"; | 8 import "package:http_server/http_server.dart"; |
| 9 import 'package:path/path.dart' as pathos; | 9 import 'package:path/path.dart' as pathos; |
| 10 import "package:unittest/unittest.dart"; | 10 import "package:unittest/unittest.dart"; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 virDir.serveFile(new File(indexUri.toFilePath()), request); | 224 virDir.serveFile(new File(indexUri.toFilePath()), request); |
| 225 }; | 225 }; |
| 226 virDir.serve(server); | 226 virDir.serve(server); |
| 227 return getAsString(server.port, '/') | 227 return getAsString(server.port, '/') |
| 228 .then((result) { | 228 .then((result) { |
| 229 expect(result, 'index file'); | 229 expect(result, 'index file'); |
| 230 }); | 230 }); |
| 231 }); | 231 }); |
| 232 | 232 |
| 233 _testVirDir('index-2', (server, dir) { | 233 _testVirDir('index-2', (server, dir) { |
| 234 new Directory('${dir.path}/dir').createSync(); |
| 235 var virDir = new VirtualDirectory(dir.path); |
| 236 virDir.allowDirectoryListing = true; |
| 237 virDir.directoryHandler = (dir2, request) { |
| 238 fail('not expected'); |
| 239 }; |
| 240 virDir.serve(server); |
| 241 return getStatusCode(server.port, '/dir', followRedirects: false) |
| 242 .then((result) { |
| 243 expect(result, 301); |
| 244 }); |
| 245 }); |
| 246 |
| 247 _testVirDir('index-3', (server, dir) { |
| 234 new File('${dir.path}/dir/index.html') | 248 new File('${dir.path}/dir/index.html') |
| 235 ..createSync(recursive: true) | 249 ..createSync(recursive: true) |
| 236 ..writeAsStringSync('index file'); | 250 ..writeAsStringSync('index file'); |
| 237 var virDir = new VirtualDirectory(dir.path); | 251 var virDir = new VirtualDirectory(dir.path); |
| 238 virDir.allowDirectoryListing = true; | 252 virDir.allowDirectoryListing = true; |
| 239 virDir.directoryHandler = (dir2, request) { | 253 virDir.directoryHandler = (dir2, request) { |
| 240 // Redirect directory-requests to index.html files. | 254 // Redirect directory-requests to index.html files. |
| 241 var indexUri = new Uri.file(dir2.path).resolve('index.html'); | 255 var indexUri = new Uri.file(dir2.path).resolve('index.html'); |
| 242 virDir.serveFile(new File(indexUri.toFilePath()), request); | 256 virDir.serveFile(new File(indexUri.toFilePath()), request); |
| 243 }; | 257 }; |
| 244 virDir.serve(server); | 258 virDir.serve(server); |
| 245 return getAsString(server.port, '/dir') | 259 return getAsString(server.port, '/dir') |
| 246 .then((result) { | 260 .then((result) { |
| 247 expect(result, 'index file'); | 261 expect(result, 'index file'); |
| 248 }); | 262 }); |
| 249 }); | 263 }); |
| 264 |
| 265 _testVirDir('index-4', (server, dir) { |
| 266 new File('${dir.path}/dir/index.html') |
| 267 ..createSync(recursive: true) |
| 268 ..writeAsStringSync('index file'); |
| 269 var virDir = new VirtualDirectory(dir.path); |
| 270 virDir.allowDirectoryListing = true; |
| 271 virDir.directoryHandler = (dir2, request) { |
| 272 // Redirect directory-requests to index.html files. |
| 273 var indexUri = new Uri.file(dir2.path).resolve('index.html'); |
| 274 virDir.serveFile(new File(indexUri.toFilePath()), request); |
| 275 }; |
| 276 virDir.serve(server); |
| 277 return getAsString(server.port, '/dir/') |
| 278 .then((result) { |
| 279 expect(result, 'index file'); |
| 280 }); |
| 281 }); |
| 250 }); | 282 }); |
| 251 }); | 283 }); |
| 252 | 284 |
| 253 group('links', () { | 285 group('links', () { |
| 254 if (!Platform.isWindows) { | 286 if (!Platform.isWindows) { |
| 255 group('follow-links', () { | 287 group('follow-links', () { |
| 256 _testVirDir('dir-link', (server, dir) { | 288 _testVirDir('dir-link', (server, dir) { |
| 257 var dir2 = new Directory('${dir.path}/dir2')..createSync(); | 289 var dir2 = new Directory('${dir.path}/dir2')..createSync(); |
| 258 var link = new Link('${dir.path}/dir3')..createSync('dir2'); | 290 var link = new Link('${dir.path}/dir3')..createSync('dir2'); |
| 259 var file = new File('${dir2.path}/file')..createSync(); | 291 var file = new File('${dir2.path}/file')..createSync(); |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 | 641 |
| 610 virDir.serve(server); | 642 virDir.serve(server); |
| 611 | 643 |
| 612 return getAsString(server.port, '/') | 644 return getAsString(server.port, '/') |
| 613 .then((result) { | 645 .then((result) { |
| 614 expect(result, 'file contents'); | 646 expect(result, 'file contents'); |
| 615 }); | 647 }); |
| 616 }); | 648 }); |
| 617 }); | 649 }); |
| 618 } | 650 } |
| OLD | NEW |