Skip to content

Conversation

hrajwade96
Copy link
Contributor

@hrajwade96 hrajwade96 commented Sep 2, 2025

Please add a note to packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md if your change requires release notes. Otherwise, add the 'release-notes-not-required' label to the PR.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read the Flutter Style Guide recently, and have followed its advice.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or there is a reason for not adding tests.

build.yaml badge

If you need help, consider asking for help on Discord.

@hrajwade96 hrajwade96 requested review from bkonyi, kenzieschmoll and a team as code owners September 2, 2025 08:54
@hrajwade96 hrajwade96 mentioned this pull request Sep 2, 2025
7 tasks
_responseBody = utf8.decode(fullRequest.responseBody!);
_requestBody = utf8.decode(fullRequest.requestBody!);
var responseMime =
responseHeaders?['content-type']?.toString().split(';').first;
Copy link
Member

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 to network/utils/http_utils.dart and add tests. Thanks!

Copy link
Contributor Author

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.

if (isTextMimeType(responseMime)) {
_responseBody = utf8.decode(fullRequest.responseBody!);
} else {
_responseBody = base64.encode(fullRequest.responseBody!);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this encode and not decode?

Copy link
Contributor Author

@hrajwade96 hrajwade96 Sep 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For text-based data like json, HTML, or XML, I've used utf8.decode since it can be directly represented and rendered without additional serialization.

For binary data such as Pdf, Pngs, or other non-text formats, I've used Base64 encode on the raw bytes so they can be safely included in the JSON-based HAR export.

When importing the HAR into a tool e.g. Chrome DevTools, the tool will automatically decode this Base64 back into its original binary form (guided by the "encoding": "base64" field present in the HAR).

}

if (fullRequest.requestBody != null) {
if (isTextMimeType(requestMime)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly to comment above, create helper function to use here and above.

Copy link
Contributor Author

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.

notifyListeners();
}
} finally {
isFetchingFullData = false;
}
}

//TODO check if all cases are handled correctly
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the TODO, thanks!

/// 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should belong in network/utils/http_utils.dart. Please also add tests. Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved the helper function, will be adding the tests soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to export certain media network requests in HAR file
2 participants