Files
sdk/tests/standalone_2/io/http_parser_header_add_test.dart
T
2021-01-23 06:07:21 +00:00

38 lines
1.1 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright (c) 2021, 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.
//
// Verify that FormatException is thrown when HttpClient userAgent has
// invalid value.
import "dart:async";
import "dart:io";
import "package:async_helper/async_helper.dart";
import "package:expect/expect.dart";
Future<void> testFormatException() async {
final server = await HttpServer.bind("127.0.0.1", 0);
server.listen((HttpRequest request) {
request.response.statusCode = 200;
request.response.close();
});
final completer = Completer<void>();
// The character is U+2019 RIGHT SINGLE QUOTATION MARK.
final client = HttpClient()..userAgent = 'Bobs browser';
asyncExpectThrows<FormatException>(() async {
try {
await client.open("CONNECT", "127.0.0.1", server.port, "/");
} finally {
client.close(force: true);
server.close();
completer.complete();
}
});
await completer.future;
}
main() {
asyncTest(testFormatException);
}