-
Notifications
You must be signed in to change notification settings - Fork 359
Network req data export improvements #9423
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 2 commits
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 |
---|---|---|
|
@@ -101,15 +101,46 @@ class DartIOHttpRequestData extends NetworkRequest { | |
); | ||
_request = updated; | ||
final fullRequest = _request as HttpProfileRequest; | ||
_responseBody = utf8.decode(fullRequest.responseBody!); | ||
_requestBody = utf8.decode(fullRequest.requestBody!); | ||
var responseMime = | ||
responseHeaders?['content-type']?.toString().split(';').first; | ||
final requestMime = | ||
requestHeaders?['content-type']?.toString().split(';').first; | ||
|
||
if (fullRequest.responseBody != null) { | ||
responseMime = normalizeContentType(responseHeaders?['content-type']); | ||
|
||
if (isTextMimeType(responseMime)) { | ||
_responseBody = utf8.decode(fullRequest.responseBody!); | ||
} else { | ||
_responseBody = base64.encode(fullRequest.responseBody!); | ||
|
||
} | ||
} | ||
|
||
if (fullRequest.requestBody != null) { | ||
if (isTextMimeType(requestMime)) { | ||
|
||
_requestBody = utf8.decode(fullRequest.requestBody!); | ||
} else { | ||
_requestBody = base64.encode(fullRequest.requestBody!); | ||
} | ||
} | ||
|
||
notifyListeners(); | ||
} | ||
} finally { | ||
isFetchingFullData = false; | ||
} | ||
} | ||
|
||
//TODO check if all cases are handled correctly | ||
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 address the TODO, thanks! |
||
String? normalizeContentType(dynamic header) { | ||
if (header is List && header.isNotEmpty) { | ||
return header.first.toString().split(';').first.trim().toLowerCase(); | ||
} else if (header is String) { | ||
return header.split(';').first.trim().toLowerCase(); | ||
} | ||
return null; | ||
} | ||
|
||
static List<Cookie> _parseCookies(List<String>? cookies) { | ||
if (cookies == null) return []; | ||
return cookies.map((cookie) => Cookie.fromSetCookieValue(cookie)).toList(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1143,3 +1143,21 @@ String devtoolsAssetsBasePath({required String origin, required String path}) { | |
pathParts.removeLast(); | ||
return '$trimmedOrigin${pathParts.join(separator)}'; | ||
} | ||
|
||
/// Returns `true` if the given [mimeType] is considered textual and can be | ||
/// safely decoded as UTF-8 without base64 encoding. | ||
/// | ||
/// This function is useful for determining whether the content of an HTTP | ||
/// request or response can be directly included in a HAR or JSON file as | ||
/// human-readable text. | ||
bool isTextMimeType(String? mimeType) { | ||
|
||
if (mimeType == null) return false; | ||
|
||
// Strip charset if present | ||
final cleanedMime = mimeType.split(';').first.trim().toLowerCase(); | ||
|
||
return cleanedMime.startsWith('text/') || | ||
cleanedMime == 'application/json' || | ||
cleanedMime == 'application/javascript' || | ||
cleanedMime == 'application/xml'; | ||
} |
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.
Could we pull this into a helper function (e.g.
getHeadersMimeType
)? That way we can use it both here and below. Please add it tonetwork/utils/http_utils.dart
and add tests. Thanks!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.
Added a helper function, will be adding the tests soon.