Skip to content

Commit

Permalink
Remove invalid status line tests and replace them with valid status l…
Browse files Browse the repository at this point in the history
…ine tests (#1018)
  • Loading branch information
brianquinlan authored Sep 15, 2023
1 parent e19094a commit decefa6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void hybridMain(StreamChannel<Object?> channel) async {
socket.writeAll(
[
statusLine,
'Access-Control-Allow-Origin: *',
'Content-Length: 0',
'\r\n', // Add \r\n at the end of this header section.
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ClientException>()),
);
},
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'));
});
});
}

0 comments on commit decefa6

Please sign in to comment.