Fix ephemeral response body reading

This commit is contained in:
Gregory Schier
2025-09-22 14:07:25 -07:00
parent 8fe50959b9
commit b3414ee60f
7 changed files with 11 additions and 13 deletions

View File

@@ -720,13 +720,10 @@ async fn cmd_format_json(text: &str) -> YaakResult<String> {
#[tauri::command] #[tauri::command]
async fn cmd_http_response_body<R: Runtime>( async fn cmd_http_response_body<R: Runtime>(
window: WebviewWindow<R>, window: WebviewWindow<R>,
app_handle: AppHandle<R>,
plugin_manager: State<'_, PluginManager>, plugin_manager: State<'_, PluginManager>,
response_id: &str, response: HttpResponse,
filter: Option<&str>, filter: Option<&str>,
) -> YaakResult<FilterResponse> { ) -> YaakResult<FilterResponse> {
let response = app_handle.db().get_http_response(response_id)?;
let body_path = match response.body_path { let body_path = match response.body_path {
None => { None => {
return Err(GenericError("Response body path not set".to_string())); return Err(GenericError("Response body path not set".to_string()));
@@ -836,7 +833,7 @@ async fn cmd_get_http_authentication_config<R: Runtime>(
AnyModel::Workspace(m) => (m.id, None), AnyModel::Workspace(m) => (m.id, None),
m => { m => {
return Err(GenericError(format!("Unsupported model to call auth config {m:?}"))); return Err(GenericError(format!("Unsupported model to call auth config {m:?}")));
}, }
}; };
let environment_chain = let environment_chain =

View File

@@ -51,7 +51,7 @@ export function ConfirmLargeResponse({ children, response }: Props) {
color="secondary" color="secondary"
variant="border" variant="border"
size="xs" size="xs"
text={() => getResponseBodyText({ responseId: response.id, filter: null })} text={() => getResponseBodyText({ response, filter: null })}
/> />
)} )}
</HStack> </HStack>

View File

@@ -44,8 +44,8 @@ const icons = {
copy_check: lucide.CopyCheck, copy_check: lucide.CopyCheck,
download: lucide.DownloadIcon, download: lucide.DownloadIcon,
ellipsis: lucide.EllipsisIcon, ellipsis: lucide.EllipsisIcon,
external_link: lucide.ExternalLinkIcon,
expand: lucide.ExpandIcon, expand: lucide.ExpandIcon,
external_link: lucide.ExternalLinkIcon,
eye: lucide.EyeIcon, eye: lucide.EyeIcon,
eye_closed: lucide.EyeOffIcon, eye_closed: lucide.EyeOffIcon,
file_code: lucide.FileCodeIcon, file_code: lucide.FileCodeIcon,
@@ -95,6 +95,7 @@ const icons = {
puzzle: lucide.PuzzleIcon, puzzle: lucide.PuzzleIcon,
refresh: lucide.RefreshCwIcon, refresh: lucide.RefreshCwIcon,
rocket: lucide.RocketIcon, rocket: lucide.RocketIcon,
rows_2: lucide.Rows2Icon,
save: lucide.SaveIcon, save: lucide.SaveIcon,
search: lucide.SearchIcon, search: lucide.SearchIcon,
send_horizontal: lucide.SendHorizonalIcon, send_horizontal: lucide.SendHorizonalIcon,

View File

@@ -7,7 +7,7 @@ export function useCopyHttpResponse(response: HttpResponse) {
return useFastMutation({ return useFastMutation({
mutationKey: ['copy_http_response', response.id], mutationKey: ['copy_http_response', response.id],
async mutationFn() { async mutationFn() {
const body = await getResponseBodyText({ responseId: response.id, filter: null }); const body = await getResponseBodyText({ response, filter: null });
copyToClipboard(body); copyToClipboard(body);
}, },
}); });

View File

@@ -66,7 +66,7 @@ export function useIntrospectGraphQL(
return setError(response.error); return setError(response.error);
} }
const bodyText = await getResponseBodyText({ responseId: response.id, filter: null }); const bodyText = await getResponseBodyText({ response, filter: null });
if (response.status < 200 || response.status >= 300) { if (response.status < 200 || response.status >= 300) {
return setError( return setError(
`Request failed with status ${response.status}.\nThe response text is:\n\n${bodyText}`, `Request failed with status ${response.status}.\nThe response text is:\n\n${bodyText}`,

View File

@@ -17,6 +17,6 @@ export function useResponseBodyText({
response.contentLength, response.contentLength,
filter ?? '', filter ?? '',
], ],
queryFn: () => getResponseBodyText({ responseId: response.id, filter }), queryFn: () => getResponseBodyText({ response, filter }),
}); });
} }

View File

@@ -4,14 +4,14 @@ import type { ServerSentEvent } from '@yaakapp-internal/sse';
import { invokeCmd } from './tauri'; import { invokeCmd } from './tauri';
export async function getResponseBodyText({ export async function getResponseBodyText({
responseId, response,
filter, filter,
}: { }: {
responseId: string; response: HttpResponse;
filter: string | null; filter: string | null;
}): Promise<string | null> { }): Promise<string | null> {
const result = await invokeCmd<FilterResponse>('cmd_http_response_body', { const result = await invokeCmd<FilterResponse>('cmd_http_response_body', {
responseId, response,
filter, filter,
}); });