-
Notifications
You must be signed in to change notification settings - Fork 387
Fix cancelled HTTP requests showing as Pending in DevTools Network tab #9685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 13 commits
45b1c2a
3ecd00f
d74f363
f5204f6
39babfa
2ad05f8
54eafea
0503e54
d9162b6
0f7a854
76cd92d
8a50293
5de8e82
d3d1ae7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,14 +135,40 @@ class DartIOHttpRequestData extends NetworkRequest { | |
|
|
||
| bool get _hasError => _request.request?.hasError ?? false; | ||
|
|
||
| DateTime? get _endTime => | ||
| _hasError ? _request.endTime : _request.response?.endTime; | ||
| DateTime? get _endTime => (_hasError || _isCancelled) | ||
| ? _request.endTime | ||
| : _request.response?.endTime; | ||
|
|
||
| bool _matchesCancellationMarker(String? value) { | ||
| if (value == null) return false; | ||
| final normalized = value.toLowerCase(); | ||
|
|
||
| // Markers used for substring matching against request / response errors | ||
| // and request event names to classify cancelled requests. | ||
| // | ||
| // Derived from observed cancellation wording in HTTP profiler payloads, | ||
| // keeping specific terms to reduce false positives. | ||
| const _cancellationMarkers = ['canceled', 'cancelled', 'aborted']; | ||
|
|
||
| return _cancellationMarkers.any(normalized.contains); | ||
| } | ||
|
|
||
| bool get _hasCancellationError { | ||
| final requestError = _request.request?.error; | ||
| final responseError = _request.response?.error; | ||
| return _matchesCancellationMarker(requestError) || | ||
| _matchesCancellationMarker(responseError); | ||
| } | ||
|
|
||
| bool get _hasCancellationEvent => | ||
| _request.events.any((event) => _matchesCancellationMarker(event.event)); | ||
|
|
||
| @override | ||
| Duration? get duration { | ||
| if (inProgress || !isValid) return null; | ||
| // Timestamps are in microseconds | ||
| return _endTime!.difference(_request.startTime); | ||
| if (inProgress || !isValid) { | ||
| return null; | ||
| } | ||
| return _endTime?.difference(_request.startTime); | ||
| } | ||
|
|
||
| /// Whether the request is safe to display in the UI. | ||
|
|
@@ -156,7 +182,7 @@ class DartIOHttpRequestData extends NetworkRequest { | |
| return { | ||
| 'method': _request.method, | ||
| 'uri': _request.uri.toString(), | ||
| if (!didFail) ...{ | ||
| if (!didFail && !_isCancelled) ...{ | ||
| 'connectionInfo': _request.request?.connectionInfo, | ||
| 'contentLength': _request.request?.contentLength, | ||
| }, | ||
|
|
@@ -227,11 +253,11 @@ class DartIOHttpRequestData extends NetworkRequest { | |
| return connectionInfo != null ? connectionInfo[_localPortKey] : null; | ||
| } | ||
|
|
||
| /// True if the HTTP request hasn't completed yet, determined by the lack of | ||
| /// an end time in the response data. | ||
| @override | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add dartdoc back |
||
| bool get inProgress => | ||
| _hasError ? !_request.isRequestComplete : !_request.isResponseComplete; | ||
| bool get inProgress { | ||
| if (_isCancelled) return false; | ||
| return _request.endTime == null; | ||
|
||
| } | ||
|
|
||
| /// All instant events logged to the timeline for this HTTP request. | ||
| List<DartIOHttpInstantEvent> get instantEvents { | ||
|
|
@@ -273,6 +299,7 @@ class DartIOHttpRequestData extends NetworkRequest { | |
| bool get didFail { | ||
| if (status == null) return false; | ||
| if (status == 'Error') return true; | ||
| if (status == 'Cancelled') return false; | ||
|
|
||
| try { | ||
| final code = int.parse(status!); | ||
|
|
@@ -301,12 +328,22 @@ class DartIOHttpRequestData extends NetworkRequest { | |
| DateTime get startTimestamp => _request.startTime; | ||
|
|
||
| @override | ||
| String? get status => | ||
| _hasError ? 'Error' : _request.response?.statusCode.toString(); | ||
| String? get status { | ||
| if (_isCancelled) return 'Cancelled'; | ||
|
|
||
| if (_hasError) return 'Error'; | ||
|
|
||
| final statusCode = _request.response?.statusCode; | ||
| if (statusCode != null) return statusCode.toString(); | ||
|
|
||
| return null; | ||
|
||
| } | ||
|
|
||
| @override | ||
| String get uri => _request.uri.toString(); | ||
|
|
||
| bool get _isCancelled => _hasCancellationError || _hasCancellationEvent; | ||
|
|
||
| String? get responseBody { | ||
| if (_request is! HttpProfileRequest) { | ||
| return null; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ abstract class CustomPointerScrollView extends BoxScrollView { | |
| super.physics, | ||
| super.shrinkWrap, | ||
| super.padding, | ||
| super.scrollCacheExtent, | ||
| super.cacheExtent, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CC @elliette ; from the PR description:
|
||
| super.semanticChildCount, | ||
| super.dragStartBehavior, | ||
| this.customPointerSignalHandler, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is now the same as it was before, revert to original code. Thanks!