Skip to content

Commit 5902e60

Browse files
author
hrishikeshrajwade
committed
mime fixes
1 parent 3d7102d commit 5902e60

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

packages/devtools_app/lib/src/shared/http/http_request_data.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,14 @@ class DartIOHttpRequestData extends NetworkRequest {
102102
);
103103
_request = updated;
104104
final fullRequest = _request as HttpProfileRequest;
105-
final responseMime =
105+
var responseMime =
106106
responseHeaders?['content-type']?.toString().split(';').first;
107107
final requestMime =
108108
requestHeaders?['content-type']?.toString().split(';').first;
109109

110110
if (fullRequest.responseBody != null) {
111+
responseMime = normalizeContentType(responseHeaders?['content-type']);
112+
111113
if (isTextMimeType(responseMime)) {
112114
_responseBody = utf8.decode(fullRequest.responseBody!);
113115
} else {
@@ -130,6 +132,16 @@ class DartIOHttpRequestData extends NetworkRequest {
130132
}
131133
}
132134

135+
//TODO check if all cases are handled correctly
136+
String? normalizeContentType(dynamic header) {
137+
if (header is List && header.isNotEmpty) {
138+
return header.first.toString().split(';').first.trim().toLowerCase();
139+
} else if (header is String) {
140+
return header.split(';').first.trim().toLowerCase();
141+
}
142+
return null;
143+
}
144+
133145
static List<Cookie> _parseCookies(List<String>? cookies) {
134146
if (cookies == null) return [];
135147
return cookies.map((cookie) => Cookie.fromSetCookieValue(cookie)).toList();

packages/devtools_app/lib/src/shared/primitives/utils.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,9 +1135,12 @@ String devtoolsAssetsBasePath({required String origin, required String path}) {
11351135
/// human-readable text.
11361136
bool isTextMimeType(String? mimeType) {
11371137
if (mimeType == null) return false;
1138-
return mimeType.startsWith('text/') ||
1139-
mimeType == 'application/json' ||
1140-
mimeType == 'application/javascript' ||
1141-
mimeType == 'application/xml' ||
1142-
mimeType == 'application/x-www-form-urlencoded';
1138+
1139+
// Strip charset if present
1140+
final cleanedMime = mimeType.split(';').first.trim().toLowerCase();
1141+
1142+
return cleanedMime.startsWith('text/') ||
1143+
cleanedMime == 'application/json' ||
1144+
cleanedMime == 'application/javascript' ||
1145+
cleanedMime == 'application/xml';
11431146
}

0 commit comments

Comments
 (0)