From decefa64234d87b1490001b8fbca6dd496d38da2 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Fri, 15 Sep 2023 14:44:29 -0700 Subject: [PATCH] Remove invalid status line tests and replace them with valid status line tests (#1018) --- .../lib/src/response_status_line_server.dart | 1 + .../lib/src/response_status_line_tests.dart | 32 +++++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/pkgs/http_client_conformance_tests/lib/src/response_status_line_server.dart b/pkgs/http_client_conformance_tests/lib/src/response_status_line_server.dart index 66d44889a1..f27aca8896 100644 --- a/pkgs/http_client_conformance_tests/lib/src/response_status_line_server.dart +++ b/pkgs/http_client_conformance_tests/lib/src/response_status_line_server.dart @@ -29,6 +29,7 @@ void hybridMain(StreamChannel channel) async { socket.writeAll( [ statusLine, + 'Access-Control-Allow-Origin: *', 'Content-Length: 0', '\r\n', // Add \r\n at the end of this header section. ], diff --git a/pkgs/http_client_conformance_tests/lib/src/response_status_line_tests.dart b/pkgs/http_client_conformance_tests/lib/src/response_status_line_tests.dart index 922236ccc1..b618fa099c 100644 --- a/pkgs/http_client_conformance_tests/lib/src/response_status_line_tests.dart +++ b/pkgs/http_client_conformance_tests/lib/src/response_status_line_tests.dart @@ -10,7 +10,10 @@ import 'package:test/test.dart'; import 'response_status_line_server_vm.dart' if (dart.library.html) 'response_status_line_server_web.dart'; -/// Tests that the [Client] correctly processes the response status line. +/// Tests that the [Client] correctly processes the response status line (e.g. +/// 'HTTP/1.1 200 OK\r\n'). +/// +/// Clients behavior varies considerably if the status line is not valid. void testResponseStatusLine(Client client) async { group('response status line', () { late String host; @@ -23,17 +26,20 @@ void testResponseStatusLine(Client client) async { host = 'localhost:${await httpServerQueue.next}'; }); - test( - 'without status code', - () async { - httpServerChannel.sink.add('HTTP/1.1 OK'); - await expectLater( - client.get(Uri.http(host, '')), - throwsA(isA()), - ); - }, - skip: - 'Enable after https://github.com/dart-lang/http/issues/1013 is fixed', - ); + test('complete', () async { + httpServerChannel.sink.add('HTTP/1.1 201 Created'); + final response = await client.get(Uri.http(host, '')); + expect(response.statusCode, 201); + expect(response.reasonPhrase, 'Created'); + }); + + test('no reason phrase', () async { + httpServerChannel.sink.add('HTTP/1.1 201'); + final response = await client.get(Uri.http(host, '')); + expect(response.statusCode, 201); + // An empty Reason-Phrase is allowed according to RFC-2616. Any of these + // interpretations seem reasonable. + expect(response.reasonPhrase, anyOf(isNull, '', 'Created')); + }); }); }