mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-31 06:23:08 +02:00
fix http response load when filter (#251)
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user