Unverified Commit ea3b08f3 authored by Yegor's avatar Yegor Committed by GitHub

Respond to HTTP POST requests with 404 in WebAssetServer (#68492)

* Respond to POST with 404 in WebAssetServer
parent 91a5a1e7
...@@ -333,6 +333,11 @@ class WebAssetServer implements AssetReader { ...@@ -333,6 +333,11 @@ class WebAssetServer implements AssetReader {
// handle requests for JavaScript source, dart sources maps, or asset files. // handle requests for JavaScript source, dart sources maps, or asset files.
@visibleForTesting @visibleForTesting
Future<shelf.Response> handleRequest(shelf.Request request) async { Future<shelf.Response> handleRequest(shelf.Request request) async {
if (request.method != 'GET') {
// Assets are served via GET only.
return shelf.Response.notFound('');
}
final String requestPath = _stripBasePath(request.url.path, basePath); final String requestPath = _stripBasePath(request.url.path, basePath);
if (requestPath == null) { if (requestPath == null) {
...@@ -969,6 +974,11 @@ class ReleaseAssetServer { ...@@ -969,6 +974,11 @@ class ReleaseAssetServer {
]; ];
Future<shelf.Response> handle(shelf.Request request) async { Future<shelf.Response> handle(shelf.Request request) async {
if (request.method != 'GET') {
// Assets are served via GET only.
return shelf.Response.notFound('');
}
Uri fileUri; Uri fileUri;
final String requestPath = _stripBasePath(request.url.path, basePath); final String requestPath = _stripBasePath(request.url.path, basePath);
......
...@@ -32,6 +32,7 @@ const List<int> kTransparentImage = <int>[ ...@@ -32,6 +32,7 @@ const List<int> kTransparentImage = <int>[
void main() { void main() {
Testbed testbed; Testbed testbed;
WebAssetServer webAssetServer; WebAssetServer webAssetServer;
ReleaseAssetServer releaseAssetServer;
Platform linux; Platform linux;
PackageConfig packages; PackageConfig packages;
Platform windows; Platform windows;
...@@ -56,6 +57,14 @@ void main() { ...@@ -56,6 +57,14 @@ void main() {
null, null,
null, null,
); );
releaseAssetServer = ReleaseAssetServer(
globals.fs.file('main.dart').uri,
fileSystem: null,
flutterRoot: null,
platform: null,
webBuildDirectory: null,
basePath: null,
);
}); });
}); });
...@@ -924,6 +933,20 @@ void main() { ...@@ -924,6 +933,20 @@ void main() {
expect(webAssetServer.defaultResponseHeaders['x-frame-options'], null); expect(webAssetServer.defaultResponseHeaders['x-frame-options'], null);
await webAssetServer.dispose(); await webAssetServer.dispose();
}); });
test('WebAssetServer responds to POST requests with 404 not found', () => testbed.run(() async {
final Response response = await webAssetServer.handleRequest(
Request('POST', Uri.parse('http://foobar/something')),
);
expect(response.statusCode, 404);
}));
test('ReleaseAssetServer responds to POST requests with 404 not found', () => testbed.run(() async {
final Response response = await releaseAssetServer.handle(
Request('POST', Uri.parse('http://foobar/something')),
);
expect(response.statusCode, 404);
}));
} }
class MockHttpServer extends Mock implements HttpServer {} class MockHttpServer extends Mock implements HttpServer {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment