mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-20 00:23:58 +01:00
Fix text decoding when no content-type
Closes https://feedback.yaak.app/p/not-rendering-response
This commit is contained in:
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user