Skip to content

Commit

Permalink
mime changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzieschmoll committed Sep 30, 2024
1 parent 7cda0e1 commit 0c49375
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/devtools_app/lib/src/shared/http/http_request_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,11 @@ class DartIOHttpRequestData extends NetworkRequest {

@override
String get type {
const defaultType = 'http';
var mime = contentType;
if (mime == null) return 'http';
if (mime == null) {
return defaultType;
}

// Extract the MIME from `contentType`.
// Example: "[text/html; charset-UTF-8]" --> "text/html"
Expand All @@ -156,24 +159,24 @@ class DartIOHttpRequestData extends NetworkRequest {
if (mime.endsWith(']')) {
mime = mime.substring(0, mime.length - 1);
}
return _extensionFromMime(mime);
return _extensionFromMime(mime) ?? defaultType;
}

/// Extracts the extension from [mime], with overrides for shortened
/// extensions of common types (e.g., jpe -> jpeg).
String _extensionFromMime(String mime) {
final extension = extensionFromMime(mime);
if (extension == 'jpe') {
String? _extensionFromMime(String mime) {
final ext = extensionFromMime(mime);
if (ext == 'jpe') {
return 'jpeg';
}
if (extension == 'htm') {
if (ext == 'htm') {
return 'html';
}
// text/plain -> conf
if (extension == 'conf') {
if (ext == 'conf') {
return 'txt';
}
return extension;
return ext;
}

@override
Expand Down

0 comments on commit 0c49375

Please sign in to comment.