OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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:io'; | 7 import 'dart:io'; |
8 import 'dart:isolate'; | 8 import 'dart:isolate'; |
9 import 'test_suite.dart'; // For TestUtils. | 9 import 'test_suite.dart'; // For TestUtils. |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 if (!requestPath.isAbsolute) { | 25 if (!requestPath.isAbsolute) { |
26 resp.statusCode = HttpStatus.NOT_FOUND; | 26 resp.statusCode = HttpStatus.NOT_FOUND; |
27 resp.outputStream.close(); | 27 resp.outputStream.close(); |
28 } else { | 28 } else { |
29 var path = basePath; | 29 var path = basePath; |
30 requestPath.segments().forEach((s) => path = path.append(s)); | 30 requestPath.segments().forEach((s) => path = path.append(s)); |
31 var file = new File(path.toNativePath()); | 31 var file = new File(path.toNativePath()); |
32 file.exists().then((exists) { | 32 file.exists().then((exists) { |
33 if (exists) { | 33 if (exists) { |
34 // Allow loading from localhost in browsers. | 34 // Allow loading from localhost in browsers. |
35 resp.headers.set("Access-Control-Allow-Origin", "*"); | 35 resp.headers.set("Access-Control-Allow-Origin", "file://"); |
| 36 resp.headers.set('Access-Control-Allow-Credentials', 'true'); |
36 file.openInputStream().pipe(resp.outputStream); | 37 file.openInputStream().pipe(resp.outputStream); |
37 } else { | 38 } else { |
38 resp.statusCode = HttpStatus.NOT_FOUND; | 39 resp.statusCode = HttpStatus.NOT_FOUND; |
39 resp.outputStream.close(); | 40 resp.outputStream.close(); |
40 } | 41 } |
41 }); | 42 }); |
42 } | 43 } |
43 }; | 44 }; |
44 | 45 |
45 _httpServer.listen(host, port); | 46 _httpServer.listen(host, port); |
46 } | 47 } |
47 | 48 |
48 terminateHttpServer() { | 49 terminateHttpServer() { |
49 if (_httpServer != null) _httpServer.close(); | 50 if (_httpServer != null) _httpServer.close(); |
50 } | 51 } |
OLD | NEW |