Serve assets with correct content-type header value (#94357)

This commit is contained in:
Sergey Fedotov
2021-12-08 23:29:07 +03:00
committed by GitHub
parent c1872c3251
commit 2a4e573dcd
2 changed files with 20 additions and 24 deletions

View File

@@ -455,14 +455,11 @@ class WebAssetServer implements AssetReader {
// Attempt to determine the file's mime type. if this is not provided some
// browsers will refuse to render images/show video etc. If the tool
// cannot determine a mime type, fall back to application/octet-stream.
String mimeType;
if (length >= 12) {
mimeType = mime.lookupMimeType(
final String mimeType = mime.lookupMimeType(
file.path,
headerBytes: await file.openRead(0, 12).first,
);
}
mimeType ??= _kDefaultMimeType;
headerBytes: await file.openRead(0, mime.defaultMagicNumbersMaxLength).first,
) ?? _kDefaultMimeType;
headers[HttpHeaders.contentLengthHeader] = length.toString();
headers[HttpHeaders.contentTypeHeader] = mimeType;
headers[HttpHeaders.etagHeader] = etag;