Upload requests handler added to test servers

Change-Id: I86d65a11afadb367ef28d91e1daeca23adeb9a19
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/221946
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
This commit is contained in:
Sergey G. Grekhov 2021-12-10 09:27:49 +00:00 committed by Commit Bot
parent e78f715541
commit b0977940fa

View file

@ -166,6 +166,7 @@ class TestingServers {
server.addHandler('/$prefixBuildDir', fileHandler);
server.addHandler('/$prefixDartDir', fileHandler);
server.addHandler('/packages', fileHandler);
server.addHandler('/upload', _handleUploadRequest);
_serverList.add(httpServer);
return server;
});
@ -237,6 +238,23 @@ class TestingServers {
});
}
void _handleUploadRequest(HttpRequest request) async {
try {
var builder = await request.fold(BytesBuilder(), (var b, var d) {
b.add(d);
return b;
});
var data = builder.takeBytes();
DebugLogger.info(
'Uploaded data: ${String.fromCharCodes(data as Iterable<int>)}');
request.response.headers.set("Access-Control-Allow-Origin", "*");
request.response.close();
} catch (e) {
DebugLogger.warning(
'HttpServer: error while processing upload request', e);
}
}
Uri _getFileUriFromRequestUri(Uri request) {
// Go to the top of the file to see an explanation of the URL path scheme.
var pathSegments = request.normalizePath().pathSegments;