mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-19 07:29:40 +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;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import type {
|
||||
HttpResponse,
|
||||
HttpResponseHeader,
|
||||
} from '@yaakapp-internal/models';
|
||||
import MimeType from 'whatwg-mimetype';
|
||||
import { getMimeTypeFromContentType } from './contentType';
|
||||
|
||||
export const BODY_TYPE_NONE = null;
|
||||
export const BODY_TYPE_GRAPHQL = 'graphql';
|
||||
@@ -61,6 +61,6 @@ export function getCharsetFromContentType(headers: HttpResponseHeader[]): string
|
||||
const contentType = getContentTypeHeader(headers);
|
||||
if (contentType == null) return null;
|
||||
|
||||
const mimeType = new MimeType(contentType);
|
||||
const mimeType = getMimeTypeFromContentType(contentType);
|
||||
return mimeType.parameters.get('charset') ?? null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user