fix: static file handlers shouldn't throw on unknown mime
curl https://flutter-dashboard.appspot.com/assets/shaders/ink_sparkle.frag
> null check
package:cocoon_service/src/request_handling/static_file_handler.dart:50:39
diff --git a/app_dart/lib/src/request_handling/static_file_handler.dart b/app_dart/lib/src/request_handling/static_file_handler.dart
index 5e77fda..6e20a1b 100644
--- a/app_dart/lib/src/request_handling/static_file_handler.dart
+++ b/app_dart/lib/src/request_handling/static_file_handler.dart
@@ -45,9 +45,10 @@
const basePath = 'build/web';
final file = fs.file('$basePath$resultPath');
if (file.existsSync()) {
- final mimeType = mimeTypeMap.containsKey(path.extension(file.path))
- ? mimeTypeMap[path.extension(file.path)]!
- : lookupMimeType(resultPath)!;
+ final mimeType =
+ mimeTypeMap[path.extension(file.path)] ??
+ lookupMimeType(resultPath) ??
+ 'application/octet-stream';
return Response.stream(
file.openRead().cast<Uint8List>(),
contentType: ContentType.parse(mimeType),
diff --git a/app_dart/test/request_handling/static_file_handler_test.dart b/app_dart/test/request_handling/static_file_handler_test.dart
index dbcae06..47f4fc1 100644
--- a/app_dart/test/request_handling/static_file_handler_test.dart
+++ b/app_dart/test/request_handling/static_file_handler_test.dart
@@ -108,5 +108,21 @@
final response = await decodeHandlerBody(body);
expect(response, 'abc');
});
+
+ test('Unknown extensions do not throw', () async {
+ fs.file('build/web/shader.frag').writeAsStringSync('abc');
+ final staticFileHandler = StaticFileHandler(
+ '/shader.frag',
+ config: config,
+ fs: fs,
+ );
+
+ final body = await tester.get(staticFileHandler);
+ expect(body, isNotNull);
+ final response = await decodeHandlerBody(body);
+ expect(response, 'abc');
+ expect(body.contentType, isNotNull);
+ expect(body.contentType!.mimeType, 'application/octet-stream');
+ });
});
}