Files
sdk/tests/standalone/io/http_headers_content_length_test.dart
T
Zichang Guo 242ce279db [dart:io] Fix Content-Length header being accidentally dropped
If the Content-Length has been set by contentLength setter, manually
setting the header to the same value will lead to the header being
dropped, since _contentLength is not updated in set() method. The method
set() will erase the header and add back the header with new value. As
_contentLength is not updated, when it adds back the new header, it
looks at _contentLength (Which is not reset) and skips the addition (
_contentLength is the same as the new value, we had the header already).

Bug: https://github.com/dart-lang/sdk/issues/42369
Change-Id: I3fba7cc332bdff0ba56e602ac810fbaeb85d2606
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151427
Commit-Queue: Zichang Guo <zichangguo@google.com>
Reviewed-by: Jonas Termansen <sortie@google.com>
2020-06-19 20:42:07 +00:00

22 lines
667 B
Dart

// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "dart:io";
import "package:expect/expect.dart";
Future<void> main() async {
final server = await HttpServer.bind("localhost", 0);
final request = await HttpClient().get("localhost", server.port, "/");
final headers = request.headers;
headers.contentLength = 100;
headers.set('Content-Length', 100);
Expect.equals('100', headers['Content-Length']?[0]);
try {
await request.close();
} catch (e) {
server.close();
}
}