Skip to content

Commit b3a6dee

Browse files
committed
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
1 parent 6dabdcb commit b3a6dee

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

app_dart/lib/src/request_handling/static_file_handler.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ final class StaticFileHandler extends RequestHandler {
4545
const basePath = 'build/web';
4646
final file = fs.file('$basePath$resultPath');
4747
if (file.existsSync()) {
48-
final mimeType = mimeTypeMap.containsKey(path.extension(file.path))
49-
? mimeTypeMap[path.extension(file.path)]!
50-
: lookupMimeType(resultPath)!;
48+
final mimeType =
49+
mimeTypeMap[path.extension(file.path)] ??
50+
lookupMimeType(resultPath) ??
51+
'application/octet-stream';
5152
return Response.stream(
5253
file.openRead().cast<Uint8List>(),
5354
contentType: ContentType.parse(mimeType),

app_dart/test/request_handling/static_file_handler_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,21 @@ void main() {
108108
final response = await decodeHandlerBody(body);
109109
expect(response, 'abc');
110110
});
111+
112+
test('Unknown extensions do not throw', () async {
113+
fs.file('build/web/shader.frag').writeAsStringSync('abc');
114+
final staticFileHandler = StaticFileHandler(
115+
'/shader.frag',
116+
config: config,
117+
fs: fs,
118+
);
119+
120+
final body = await tester.get(staticFileHandler);
121+
expect(body, isNotNull);
122+
final response = await decodeHandlerBody(body);
123+
expect(response, 'abc');
124+
expect(body.contentType, isNotNull);
125+
expect(body.contentType!.mimeType, 'application/octet-stream');
126+
});
111127
});
112128
}

0 commit comments

Comments
 (0)