fix http response load when filter (#251)

This commit is contained in:
Hao Xiang
2025-09-17 04:01:00 +08:00
committed by GitHub
parent 8c3ed60579
commit fec64b5c02
11 changed files with 97 additions and 102 deletions

View File

@@ -1,23 +1,25 @@
import { readFile } from '@tauri-apps/plugin-fs';
import type { HttpResponse } from '@yaakapp-internal/models';
import type { FilterResponse } from '@yaakapp-internal/plugins';
import type { ServerSentEvent } from '@yaakapp-internal/sse';
import { getCharsetFromContentType } from './model_util';
import { invokeCmd } from './tauri';
export async function getResponseBodyText(response: HttpResponse): Promise<string | null> {
if (!response.bodyPath) {
return null;
export async function getResponseBodyText({
responseId,
filter,
}: {
responseId: string;
filter: string | null;
}): Promise<string | null> {
const result = await invokeCmd<FilterResponse>('cmd_http_response_body', {
responseId,
filter,
});
if (result.error) {
throw new Error(result.error);
}
const bytes = await readFile(response.bodyPath);
const charset = getCharsetFromContentType(response.headers);
return new TextDecoder(charset ?? 'utf-8', { fatal: false }).decode(bytes);
}
export async function getResponseBodyBlob(response: HttpResponse): Promise<Uint8Array | null> {
if (!response.bodyPath) return null;
return readFile(response.bodyPath);
return result.content;
}
export async function getResponseBodyEventSource(