Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
2a4e573d
Unverified
Commit
2a4e573d
authored
Dec 08, 2021
by
Sergey Fedotov
Committed by
GitHub
Dec 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Serve assets with correct content-type header value (#94357)
parent
c1872c32
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
18 deletions
+14
-18
devfs_web.dart
packages/flutter_tools/lib/src/isolated/devfs_web.dart
+4
-7
devfs_web_test.dart
.../flutter_tools/test/general.shard/web/devfs_web_test.dart
+10
-11
No files found.
packages/flutter_tools/lib/src/isolated/devfs_web.dart
View file @
2a4e573d
...
@@ -455,14 +455,11 @@ class WebAssetServer implements AssetReader {
...
@@ -455,14 +455,11 @@ class WebAssetServer implements AssetReader {
// Attempt to determine the file's mime type. if this is not provided some
// 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
// browsers will refuse to render images/show video etc. If the tool
// cannot determine a mime type, fall back to application/octet-stream.
// cannot determine a mime type, fall back to application/octet-stream.
String
mimeType
;
final
String
mimeType
=
mime
.
lookupMimeType
(
if
(
length
>=
12
)
{
mimeType
=
mime
.
lookupMimeType
(
file
.
path
,
file
.
path
,
headerBytes:
await
file
.
openRead
(
0
,
12
).
first
,
headerBytes:
await
file
.
openRead
(
0
,
mime
.
defaultMagicNumbersMaxLength
).
first
,
);
)
??
_kDefaultMimeType
;
}
mimeType
??=
_kDefaultMimeType
;
headers
[
HttpHeaders
.
contentLengthHeader
]
=
length
.
toString
();
headers
[
HttpHeaders
.
contentLengthHeader
]
=
length
.
toString
();
headers
[
HttpHeaders
.
contentTypeHeader
]
=
mimeType
;
headers
[
HttpHeaders
.
contentTypeHeader
]
=
mimeType
;
headers
[
HttpHeaders
.
etagHeader
]
=
etag
;
headers
[
HttpHeaders
.
etagHeader
]
=
etag
;
...
...
packages/flutter_tools/test/general.shard/web/devfs_web_test.dart
View file @
2a4e573d
...
@@ -539,31 +539,30 @@ void main() {
...
@@ -539,31 +539,30 @@ void main() {
expect
((
await
response
.
read
().
toList
()).
first
,
source
.
readAsBytesSync
());
expect
((
await
response
.
read
().
toList
()).
first
,
source
.
readAsBytesSync
());
}));
}));
test
(
'serves asset files files from in filesystem with unknown mime type and length > 12'
,
()
=>
testbed
.
run
(()
async
{
test
(
'serves asset files from in filesystem with known mime type and empty content'
,
()
=>
testbed
.
run
(()
async
{
final
File
source
=
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
'build'
,
'flutter_assets'
,
'foo'
))
final
File
source
=
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
'web'
,
'foo.js'
))
..
createSync
(
recursive:
true
)
..
createSync
(
recursive:
true
);
..
writeAsBytesSync
(
List
<
int
>.
filled
(
100
,
0
));
final
Response
response
=
await
webAssetServer
final
Response
response
=
await
webAssetServer
.
handleRequest
(
Request
(
'GET'
,
Uri
.
parse
(
'http://foobar/assets/foo
'
)));
.
handleRequest
(
Request
(
'GET'
,
Uri
.
parse
(
'http://foobar/foo.js
'
)));
expect
(
response
.
headers
,
allOf
(<
Matcher
>[
expect
(
response
.
headers
,
allOf
(<
Matcher
>[
containsPair
(
HttpHeaders
.
contentLengthHeader
,
'
10
0'
),
containsPair
(
HttpHeaders
.
contentLengthHeader
,
'0'
),
containsPair
(
HttpHeaders
.
contentTypeHeader
,
'application/
octet-stream
'
),
containsPair
(
HttpHeaders
.
contentTypeHeader
,
'application/
javascript
'
),
]));
]));
expect
((
await
response
.
read
().
toList
()).
first
,
source
.
readAsBytesSync
());
expect
((
await
response
.
read
().
toList
()).
first
,
source
.
readAsBytesSync
());
}));
}));
test
(
'serves asset files files from in filesystem with unknown mime type
and length < 12
'
,
()
=>
testbed
.
run
(()
async
{
test
(
'serves asset files files from in filesystem with unknown mime type'
,
()
=>
testbed
.
run
(()
async
{
final
File
source
=
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
'build'
,
'flutter_assets'
,
'foo'
))
final
File
source
=
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
'build'
,
'flutter_assets'
,
'foo'
))
..
createSync
(
recursive:
true
)
..
createSync
(
recursive:
true
)
..
writeAsBytesSync
(
<
int
>[
1
,
2
,
3
]
);
..
writeAsBytesSync
(
List
<
int
>.
filled
(
100
,
0
)
);
final
Response
response
=
await
webAssetServer
final
Response
response
=
await
webAssetServer
.
handleRequest
(
Request
(
'GET'
,
Uri
.
parse
(
'http://foobar/assets/foo'
)));
.
handleRequest
(
Request
(
'GET'
,
Uri
.
parse
(
'http://foobar/assets/foo'
)));
expect
(
response
.
headers
,
allOf
(<
Matcher
>[
expect
(
response
.
headers
,
allOf
(<
Matcher
>[
containsPair
(
HttpHeaders
.
contentLengthHeader
,
'
3
'
),
containsPair
(
HttpHeaders
.
contentLengthHeader
,
'
100
'
),
containsPair
(
HttpHeaders
.
contentTypeHeader
,
'application/octet-stream'
),
containsPair
(
HttpHeaders
.
contentTypeHeader
,
'application/octet-stream'
),
]));
]));
expect
((
await
response
.
read
().
toList
()).
first
,
source
.
readAsBytesSync
());
expect
((
await
response
.
read
().
toList
()).
first
,
source
.
readAsBytesSync
());
...
@@ -594,7 +593,7 @@ void main() {
...
@@ -594,7 +593,7 @@ void main() {
expect
(
response
.
headers
,
allOf
(<
Matcher
>[
expect
(
response
.
headers
,
allOf
(<
Matcher
>[
containsPair
(
HttpHeaders
.
contentLengthHeader
,
'3'
),
containsPair
(
HttpHeaders
.
contentLengthHeader
,
'3'
),
containsPair
(
HttpHeaders
.
contentTypeHeader
,
'
application/octet-stream
'
),
containsPair
(
HttpHeaders
.
contentTypeHeader
,
'
text/x-dart
'
),
]));
]));
expect
((
await
response
.
read
().
toList
()).
first
,
source
.
readAsBytesSync
());
expect
((
await
response
.
read
().
toList
()).
first
,
source
.
readAsBytesSync
());
}));
}));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment