我正在通过HttpServer发送Dart文件,但每当我拿到它时,Chrome都说:
"Resource interpreted as Script but transferred with MIME type application/dart: "http://localhost:8000/dart/game.dart"."
客户的行是:
<script type="application/dart" src="dart/game.dart"></script>
提供文件的行是:
if(new RegExp("/dart/(.*)").hasMatch(uri)){
new File("static/" + uri.substring(1)).exists().then((bool exists){
if(!exists) return;
new File("static/" + uri.substring(1)).readAsString().then((String contents){
if(uri.substring(uri.length - 2, uri.length) == "js")
request.response.headers.contentType = new ContentType("application", "javascript", charset: "utf-8");
else
request.response.headers.contentType = new ContentType("application", "dart");
request.response.write(contents);
request.response.close();
});
});
}
当我直接访问网址时,它会将文件提供给我;和谷歌Chrome网络说:
Remote Address:127.0.0.1:8000
Request URL:http://localhost:8000/dart/game.dart
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Host:localhost:8000
Referer:http://localhost:8000/play
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36
Response Headersview source
content-type:application/dart
transfer-encoding:chunked
x-content-type-options:nosniff
x-frame-options:SAMEORIGIN
x-xss-protection:1; mode=block
我该怎么办?