[ddc] Update content-length to not be negative

The null safety migration changed the 'content-length' from null to
-1 but a separate change at the same time disallowed negative
values.

Now returning what the 'content-length' would be if the request was
a GET.

Fixes: https://github.com/dart-lang/sdk/issues/49483

Change-Id: I2ba3ce1fb604c0fac50f354f56b3d29de6465caa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/252005
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
This commit is contained in:
Nicholas Shahan 2022-07-21 00:45:35 +00:00 committed by Commit Bot
parent 0add39a68e
commit 3526954466

View file

@ -936,22 +936,15 @@ class TestAssetServer {
try {
var entity = fileSystem.entityForUri(uri);
if (await entity.existsAsyncIfPossible()) {
if (request.method == 'HEAD') {
var headers = {
'content-length': '-1',
...request.headers,
};
return Response.ok(null, headers: headers);
}
if (request.method == 'GET') {
if (request.method == 'HEAD' || request.method == 'GET') {
// 'readAsBytes'
var contents = await entity.readAsBytesAsyncIfPossible();
var headers = {
'content-length': '${contents.length}',
...request.headers,
};
return Response.ok(contents, headers: headers);
return Response.ok(request.method == 'GET' ? contents : null,
headers: headers);
}
}
return Response.notFound(path);