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 import '../../../pkg/args/lib/args.dart'; | 10 import '../../../pkg/args/lib/args.dart'; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 var requestPathStr = requestPath.toNativePath().substring( | 88 var requestPathStr = requestPath.toNativePath().substring( |
89 requestPath.toNativePath().indexOf(packagesDirName)); | 89 requestPath.toNativePath().indexOf(packagesDirName)); |
90 path = packageRootDir.append(requestPathStr); | 90 path = packageRootDir.append(requestPathStr); |
91 file = new File(path.toNativePath()); | 91 file = new File(path.toNativePath()); |
92 } | 92 } |
93 file.exists().then((exists) { | 93 file.exists().then((exists) { |
94 if (exists) { | 94 if (exists) { |
95 if (allowedPort != -1) { | 95 if (allowedPort != -1) { |
96 // Allow loading from localhost:$allowedPort in browsers. | 96 // Allow loading from localhost:$allowedPort in browsers. |
97 resp.headers.set("Access-Control-Allow-Origin", | 97 resp.headers.set("Access-Control-Allow-Origin", |
98 "http://127.0.0.1:${allowedPort+1}"); | 98 "http://127.0.0.1:$allowedPort"); |
99 resp.headers.set('Access-Control-Allow-Credentials', 'true'); | 99 resp.headers.set('Access-Control-Allow-Credentials', 'true'); |
100 } else { | 100 } else { |
101 // No allowedPort specified. Allow from anywhere (but cross-origin | 101 // No allowedPort specified. Allow from anywhere (but cross-origin |
102 // requests *with credentials* will fail because you can't use "*"). | 102 // requests *with credentials* will fail because you can't use "*"). |
103 resp.headers.set("Access-Control-Allow-Origin", "*"); | 103 resp.headers.set("Access-Control-Allow-Origin", "*"); |
104 } | 104 } |
105 if (path.toNativePath().endsWith('.html')) { | 105 if (path.toNativePath().endsWith('.html')) { |
106 resp.headers.set('Content-Type', 'text/html'); | 106 resp.headers.set('Content-Type', 'text/html'); |
107 } else if (path.toNativePath().endsWith('.js')) { | 107 } else if (path.toNativePath().endsWith('.js')) { |
108 resp.headers.set('Content-Type', 'application/javascript'); | 108 resp.headers.set('Content-Type', 'application/javascript'); |
(...skipping 25 matching lines...) Expand all Loading... |
134 }); | 134 }); |
135 | 135 |
136 httpServer.listen(host, port); | 136 httpServer.listen(host, port); |
137 serverList.add(httpServer); | 137 serverList.add(httpServer); |
138 } | 138 } |
139 | 139 |
140 static terminateHttpServers() { | 140 static terminateHttpServers() { |
141 for (var server in serverList) server.close(); | 141 for (var server in serverList) server.close(); |
142 } | 142 } |
143 } | 143 } |
OLD | NEW |