Fix text decoding when no content-type

Closes https://feedback.yaak.app/p/not-rendering-response
This commit is contained in:
Gregory Schier
2025-04-21 06:54:03 -07:00
parent faca29c789
commit 6d4fdc91fe
4 changed files with 6 additions and 16 deletions

View File

@@ -5,18 +5,14 @@ import { getCharsetFromContentType } from './model_util';
import { invokeCmd } from './tauri';
export async function getResponseBodyText(response: HttpResponse): Promise<string | null> {
if (!response.bodyPath) return null;
if (!response.bodyPath) {
return null;
}
const bytes = await readFile(response.bodyPath);
const charset = getCharsetFromContentType(response.headers);
try {
return new TextDecoder(charset ?? 'utf-8', { fatal: true }).decode(bytes);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (err) {
// Failed to decode as text, so return null
return null;
}
return new TextDecoder(charset ?? 'utf-8', { fatal: false }).decode(bytes);
}
export async function getResponseBodyBlob(response: HttpResponse): Promise<Uint8Array | null> {