Skip to content

Commit

Permalink
remove
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan committed Sep 15, 2023
1 parent d69c874 commit f4052b5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 68 deletions.
15 changes: 3 additions & 12 deletions pkgs/cronet_http/lib/src/cronet_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,13 @@ jb.UrlRequestCallbackProxy_UrlRequestCallbackInterface _urlRequestCallbacks(
contentLength = int.parse(contentLengthHeader);
}

final statusText =
responseInfo.getHttpStatusText().toDartString(releaseOriginal: true);
if (statusText.isEmpty) {
// responseInfo.getHttpStatusText() will be empty for any failure to
// parse the Status-Line but responseInfo.getHttpStatusCode() will
// return 200.
responseCompleter.completeError(ClientException(
'Invalid Status-Line',
request.url,
));
}
responseCompleter.complete(StreamedResponse(
responseStream!.stream,
responseInfo.getHttpStatusCode(),
contentLength: contentLength,
reasonPhrase: statusText,
reasonPhrase: responseInfo
.getHttpStatusText()
.toDartString(releaseOriginal: true),
request: request,
isRedirect: false,
headers: responseHeaders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('defaultSessionConfiguration', () {
testAll(CupertinoClient.defaultSessionConfiguration,
reasonableInvalidStatusLineHandling: false);
testAll(CupertinoClient.defaultSessionConfiguration);
});
group('fromSessionConfiguration', () {
final config = URLSessionConfiguration.ephemeralSessionConfiguration();
testAll(() => CupertinoClient.fromSessionConfiguration(config),
canWorkInIsolates: false, reasonableInvalidStatusLineHandling: false);
canWorkInIsolates: false);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,14 @@ export 'src/server_errors_test.dart' show testServerErrors;
/// If [canWorkInIsolates] is `false` then tests that require that the [Client]
/// work in Isolates other than the main isolate will be skipped.
///
/// If [reasonableInvalidStatusLineHandling] is `false` the tests related to
/// invalid `Status-Line`s are skipped.
///
/// The tests are run against a series of HTTP servers that are started by the
/// tests. If the tests are run in the browser, then the test servers are
/// started in another process. Otherwise, the test servers are run in-process.
void testAll(Client Function() clientFactory,
{bool canStreamRequestBody = true,
bool canStreamResponseBody = true,
bool redirectAlwaysAllowed = false,
bool canWorkInIsolates = true,
bool reasonableInvalidStatusLineHandling = true}) {
bool canWorkInIsolates = true}) {
testRequestBody(clientFactory());
testRequestBodyStreamed(clientFactory(),
canStreamRequestBody: canStreamRequestBody);
Expand All @@ -70,8 +66,7 @@ void testAll(Client Function() clientFactory,
canStreamResponseBody: canStreamResponseBody);
testRequestHeaders(clientFactory());
testResponseHeaders(clientFactory());
testResponseStatusLine(clientFactory(),
reasonableInvalidStatusLineHandling: reasonableInvalidStatusLineHandling);
testResponseStatusLine(clientFactory());
testRedirect(clientFactory(), redirectAlwaysAllowed: redirectAlwaysAllowed);
testServerErrors(clientFactory());
testCompressedResponseBody(clientFactory());
Expand Down
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 @@ -13,10 +13,8 @@ import 'response_status_line_server_vm.dart'
/// Tests that the [Client] correctly processes the response status line (e.g.
/// 'HTTP/1.1 200 OK\r\n').
///
/// If [reasonableInvalidStatusLineHandling] is `false` the tests related to
/// invalid `Status-Line`s are skipped.
void testResponseStatusLine(Client client,
{bool reasonableInvalidStatusLineHandling = true}) async {
/// Clients behavior varies considerably if the status line is not valid.
void testResponseStatusLine(Client client) async {
group('response status line', () {
late String host;
late StreamChannel<Object?> httpServerChannel;
Expand All @@ -28,53 +26,18 @@ void testResponseStatusLine(Client client,
host = 'localhost:${await httpServerQueue.next}';
});

test('valid', () async {
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');
});

group('invalid', () {
test(
'without HTTP version',
() async {
httpServerChannel.sink.add('201 Created');
await expectLater(
client.get(Uri.http(host, '')),
throwsA(isA<ClientException>()),
);
},
);

test(
'without status code',
() async {
httpServerChannel.sink.add('HTTP/1.1 OK');
await expectLater(
client.get(Uri.http(host, '')),
throwsA(isA<ClientException>()),
);
},
);

test(
'without reason phrase',
() async {
httpServerChannel.sink.add('HTTP/1.1 201');
try {
final response = await client.get(Uri.http(host, ''));
expect(response.statusCode, 201);
// All of these responses seem reasonable.
expect(response.reasonPhrase, anyOf(isNull, '', 'Created'));
} on ClientException {
// A Reason-Phrase is required according to RFC-2616
}
},
);
},
skip: reasonableInvalidStatusLineHandling
? false
: 'does handle invalid request lines in a sensible way');
test('no reason phrase', () async {
httpServerChannel.sink.add('HTTP/1.1 201');
final response = await client.get(Uri.http(host, ''));
expect(response.statusCode, 201);
expect(response.reasonPhrase, anyOf(isNull, '', 'Created'));
});
});
}

0 comments on commit f4052b5

Please sign in to comment.