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 {
// handle requests for JavaScript source, dart sources maps, or asset files.
@visibleForTesting
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);
if (requestPath == null) {
......@@ -969,6 +974,11 @@ class ReleaseAssetServer {
];
Future<shelf.Response> handle(shelf.Request request) async {
if (request.method != 'GET') {
// Assets are served via GET only.
return shelf.Response.notFound('');
}
Uri fileUri;
final String requestPath = _stripBasePath(request.url.path, basePath);
......
......@@ -32,6 +32,7 @@ const List<int> kTransparentImage = <int>[
void main() {
Testbed testbed;
WebAssetServer webAssetServer;
ReleaseAssetServer releaseAssetServer;
Platform linux;
PackageConfig packages;
Platform windows;
......@@ -56,6 +57,14 @@ void main() {
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() {
expect(webAssetServer.defaultResponseHeaders['x-frame-options'], null);
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 {}
......
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