Skip to content

Commit

Permalink
Update cupertino_client.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan committed Mar 29, 2024
1 parent d3a48a3 commit 81deb02
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions pkgs/cupertino_http/lib/src/cupertino_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,13 @@ class CupertinoClient extends BaseClient {
..headersCommaValues = request.headers
..maxRedirects = request.maxRedirects;

if (profile != null && request.contentLength != null) {
profile.requestData.headersListValues = {
'Content-Length': ['${request.contentLength}'],
...profile.requestData.headers!
};
}

final urlRequest = MutableURLRequest.fromUrl(request.url)
..httpMethod = request.method;

Expand All @@ -315,12 +322,6 @@ class CupertinoClient extends BaseClient {
// `httpBodyStream` requires a lot of expensive setup and data passing.
urlRequest.httpBody = Data.fromList(request.bodyBytes);
profile?.requestData.bodySink.add(request.bodyBytes);
if (profile != null) {
final headers =
Map<String, List<String>>.from(profile.requestData.headers!);
headers['Content-Length'] = ['${request.contentLength}'];
profile.requestData.headersListValues = headers;
}
} else if (await _hasData(stream) case (true, final s)) {
// If the request is supposed to be bodyless (e.g. GET requests)
// then setting `httpBodyStream` will cause the request to fail -
Expand All @@ -331,12 +332,6 @@ class CupertinoClient extends BaseClient {
final splitter = StreamSplitter(s);
urlRequest.httpBodyStream = splitter.split();
unawaited(profile.requestData.bodySink.addStream(splitter.split()));
if (request.contentLength != null) {
final headers =
Map<String, List<String>>.from(profile.requestData.headers!);
headers['Content-Length'] = ['${request.contentLength}'];
profile.requestData.headersListValues = headers;
}
}
}

Expand Down

0 comments on commit 81deb02

Please sign in to comment.