Skip to content

Commit

Permalink
Throw an exception on incorrect status lines.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan committed Sep 13, 2023
1 parent eafbbb0 commit aed7779
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
16 changes: 13 additions & 3 deletions pkgs/cronet_http/lib/src/cronet_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,23 @@ jb.UrlRequestCallbackProxy_UrlRequestCallbackInterface _urlRequestCallbacks(
case final contentLengthHeader?:
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: responseInfo
.getHttpStatusText()
.toDartString(releaseOriginal: true),
reasonPhrase: statusText,
request: request,
isRedirect: false,
headers: responseHeaders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ void testResponseStatusLine(Client client) async {
host = 'localhost:${await httpServerQueue.next}';
});

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

test(
'without status code',
() async {
Expand All @@ -32,8 +43,17 @@ void testResponseStatusLine(Client client) async {
throwsA(isA<ClientException>()),
);
},
skip:
'Enable after https://github.com/dart-lang/http/issues/1013 is fixed',
);

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

0 comments on commit aed7779

Please sign in to comment.