serve correct content type from debug server (#42701)

This commit is contained in:
Jonah Williams
2019-10-15 15:25:57 -07:00
committed by GitHub
parent 21a18fbe16
commit ad1d67e0a1
2 changed files with 44 additions and 1 deletions

View File

@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:typed_data';
import 'package:archive/archive.dart';
import 'package:build_daemon/client.dart';
@@ -17,6 +18,7 @@ import 'package:meta/meta.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:shelf_proxy/shelf_proxy.dart';
import 'package:mime/mime.dart' as mime;
import '../artifacts.dart';
import '../asset.dart';
@@ -501,7 +503,14 @@ class DebugAssetServer extends AssetServer {
final String assetPath = request.url.path.replaceFirst('assets/', '');
final File file = fs.file(fs.path.join(getAssetBuildDirectory(), assetPath));
if (file.existsSync()) {
return Response.ok(file.readAsBytesSync());
final Uint8List bytes = file.readAsBytesSync();
// Fallback to "application/octet-stream" on null which
// makes no claims as to the structure of the data.
final String mimeType = mime.lookupMimeType(file.path, headerBytes: bytes)
?? 'application/octet-stream';
return Response.ok(bytes, headers: <String, String>{
'Content-Type': mimeType,
});
} else {
return Response.notFound('');
}