mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-18 14:59:42 +02:00
Don't load response when blocking large responses
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import MimeType from 'whatwg-mimetype';
|
||||
import type { EditorProps } from '../components/core/Editor/Editor';
|
||||
|
||||
export function languageFromContentType(
|
||||
@@ -40,10 +41,39 @@ export function isJSON(content: string | null | undefined): boolean {
|
||||
if (typeof content !== 'string') return false;
|
||||
|
||||
try {
|
||||
JSON.parse(content)
|
||||
JSON.parse(content);
|
||||
return true;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function isProbablyTextContentType(contentType: string | null): boolean {
|
||||
if (contentType == null) return false;
|
||||
|
||||
const mimeType = getMimeTypeFromContentType(contentType).essence;
|
||||
const normalized = mimeType.toLowerCase();
|
||||
|
||||
// Check if it starts with "text/"
|
||||
if (normalized.startsWith('text/')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Common text mimetypes and suffixes
|
||||
return [
|
||||
'application/json',
|
||||
'application/xml',
|
||||
'application/javascript',
|
||||
'application/yaml',
|
||||
'+json',
|
||||
'+xml',
|
||||
'+yaml',
|
||||
'+text',
|
||||
].some((textType) => normalized === textType || normalized.endsWith(textType));
|
||||
}
|
||||
|
||||
export function getMimeTypeFromContentType(contentType: string) {
|
||||
const mimeType = new MimeType(contentType);
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user