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
a60a47ae
Unverified
Commit
a60a47ae
authored
Oct 31, 2019
by
Jonah Williams
Committed by
GitHub
Oct 31, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Serve correct mime type on release dev server (#43907)
parent
353721a1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
13 deletions
+50
-13
web_fs.dart
packages/flutter_tools/lib/src/build_runner/web_fs.dart
+8
-13
asset_server_test.dart
...utter_tools/test/general.shard/web/asset_server_test.dart
+42
-0
No files found.
packages/flutter_tools/lib/src/build_runner/web_fs.dart
View file @
a60a47ae
...
...
@@ -354,28 +354,23 @@ class ReleaseAssetServer extends AssetServer {
final
Uri
artifactUri
=
fs
.
directory
(
getWebBuildDirectory
()).
uri
.
resolveUri
(
request
.
url
);
final
File
file
=
fs
.
file
(
artifactUri
);
if
(
file
.
existsSync
())
{
return
Response
.
ok
(
file
.
readAsBytesSync
(),
headers:
<
String
,
String
>{
'Content-Type'
:
_guessExtension
(
file
),
final
Uint8List
bytes
=
file
.
readAsBytesSync
();
// Fallback to "application/octet-stream" on null which
// makes no claims as to the structure of the data.
final
String
mimeType
=
mime
.
lookupMimeType
(
file
.
path
,
headerBytes:
bytes
)
??
'application/octet-stream'
;
return
Response
.
ok
(
bytes
,
headers:
<
String
,
String
>{
'Content-Type'
:
mimeType
,
});
}
if
(
request
.
url
.
path
==
''
)
{
final
File
file
=
fs
.
file
(
fs
.
path
.
join
(
getWebBuildDirectory
(),
'index.html'
));
return
Response
.
ok
(
file
.
readAsBytesSync
(),
headers:
<
String
,
String
>{
'Content-Type'
:
_guessExtension
(
file
)
,
'Content-Type'
:
'text/html'
,
});
}
return
Response
.
notFound
(
''
);
}
String
_guessExtension
(
File
file
)
{
switch
(
fs
.
path
.
extension
(
file
.
path
))
{
case
'.js'
:
return
'text/javascript'
;
case
'.html'
:
return
'text/html'
;
}
return
'text'
;
}
}
class
DebugAssetServer
extends
AssetServer
{
...
...
packages/flutter_tools/test/general.shard/web/asset_server_test.dart
View file @
a60a47ae
...
...
@@ -78,4 +78,46 @@ void main() {
expect
(
response
.
statusCode
,
404
);
}));
test
(
'release asset server serves correct mime type and content length for png'
,
()
=>
testbed
.
run
(()
async
{
assetServer
=
ReleaseAssetServer
();
fs
.
file
(
fs
.
path
.
join
(
'build'
,
'web'
,
'assets'
,
'foo.png'
))
..
createSync
(
recursive:
true
)
..
writeAsBytesSync
(
kTransparentImage
);
final
Response
response
=
await
assetServer
.
handle
(
Request
(
'GET'
,
Uri
.
parse
(
'http://localhost:8080/assets/foo.png'
)));
expect
(
response
.
headers
,
<
String
,
String
>{
'Content-Type'
:
'image/png'
,
'content-length'
:
'64'
,
});
}));
test
(
'release asset server serves correct mime type and content length for JavaScript'
,
()
=>
testbed
.
run
(()
async
{
assetServer
=
ReleaseAssetServer
();
fs
.
file
(
fs
.
path
.
join
(
'build'
,
'web'
,
'assets'
,
'foo.js'
))
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
'function main() {}'
);
final
Response
response
=
await
assetServer
.
handle
(
Request
(
'GET'
,
Uri
.
parse
(
'http://localhost:8080/assets/foo.js'
)));
expect
(
response
.
headers
,
<
String
,
String
>{
'Content-Type'
:
'application/javascript'
,
'content-length'
:
'18'
,
});
}));
test
(
'release asset server serves correct mime type and content length for html'
,
()
=>
testbed
.
run
(()
async
{
assetServer
=
ReleaseAssetServer
();
fs
.
file
(
fs
.
path
.
join
(
'build'
,
'web'
,
'assets'
,
'foo.html'
))
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
'<!doctype html><html></html>'
);
final
Response
response
=
await
assetServer
.
handle
(
Request
(
'GET'
,
Uri
.
parse
(
'http://localhost:8080/assets/foo.html'
)));
expect
(
response
.
headers
,
<
String
,
String
>{
'Content-Type'
:
'text/html'
,
'content-length'
:
'28'
,
});
}));
}
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