From 21f031c2070448bf28e2d3dd06ab3ac868c29315 Mon Sep 17 00:00:00 2001 From: thosakwe Date: Thu, 15 Jun 2017 23:13:01 -0400 Subject: [PATCH] octet stream --- lib/src/file_info.dart | 2 +- lib/src/virtual_directory.dart | 4 ++-- pubspec.yaml | 2 +- test/all_test.dart | 8 ++++++++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/src/file_info.dart b/lib/src/file_info.dart index f0394b64..2e1a6c16 100644 --- a/lib/src/file_info.dart +++ b/lib/src/file_info.dart @@ -26,7 +26,7 @@ abstract class FileInfo { factory FileInfo.fromFile(File file) => new _FileInfoImpl( () => file.openRead(), file.absolute.path, - lookupMimeType(file.path), + lookupMimeType(file.path) ?? 'application/octet-stream', file.statSync().modified); /// Creates a [FileInfo] describing a file that might not even exists to begin with. diff --git a/lib/src/virtual_directory.dart b/lib/src/virtual_directory.dart index 7d4a95c0..5c098eca 100644 --- a/lib/src/virtual_directory.dart +++ b/lib/src/virtual_directory.dart @@ -262,8 +262,8 @@ class VirtualDirectory implements AngelPlugin { void _ensureContentTypeAllowed(String mimeType, RequestContext req) { var value = req.headers.value(HttpHeaders.ACCEPT); bool acceptable = value == null || - value.isEmpty || - value?.contains(mimeType) == true || + value?.isNotEmpty != true || + (mimeType?.isNotEmpty == true && value?.contains(mimeType) == true) || value?.contains('*/*') == true; if (!acceptable) throw new AngelHttpException( diff --git a/pubspec.yaml b/pubspec.yaml index 8428edde..013b9cf7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ environment: sdk: ">=1.19.0" homepage: https://github.com/angel-dart/static author: Tobe O -version: 1.2.2+1 +version: 1.2.2+3 dependencies: angel_framework: ^1.0.0-dev cli_util: ^0.1.1 diff --git a/test/all_test.dart b/test/all_test.dart index a5fa5516..892007de 100644 --- a/test/all_test.dart +++ b/test/all_test.dart @@ -64,4 +64,12 @@ main() { var response = await client.get("$url/virtual"); expect(response.body, equals("index!")); }); + + test('chrome accept', () async { + var response = await client.get("$url/virtual", headers: { + HttpHeaders.ACCEPT: + 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' + }); + expect(response.body, equals("index!")); + }); }