From d3cda19be23da7e46bdcd079231c31290e05d0be Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Sun, 29 Jun 2025 07:30:07 -0700 Subject: [PATCH] Hide large request bodies by default --- .../components/ConfirmLargeRequestBody.tsx | 76 ++++++++++ src-web/components/HttpRequestPane.tsx | 135 +++++++++--------- 2 files changed, 145 insertions(+), 66 deletions(-) create mode 100644 src-web/components/ConfirmLargeRequestBody.tsx diff --git a/src-web/components/ConfirmLargeRequestBody.tsx b/src-web/components/ConfirmLargeRequestBody.tsx new file mode 100644 index 00000000..3ec50da4 --- /dev/null +++ b/src-web/components/ConfirmLargeRequestBody.tsx @@ -0,0 +1,76 @@ +import type { HttpRequest } from '@yaakapp-internal/models'; +import { patchModel } from '@yaakapp-internal/models'; +import { type ReactNode } from 'react'; +import { useToggle } from '../hooks/useToggle'; +import { showConfirm } from '../lib/confirm'; +import { Banner } from './core/Banner'; +import { Button } from './core/Button'; +import { InlineCode } from './core/InlineCode'; +import { Link } from './core/Link'; +import { SizeTag } from './core/SizeTag'; +import { HStack } from './core/Stacks'; + +interface Props { + children: ReactNode; + request: HttpRequest; +} + +const LARGE_TEXT_BYTES = 2 * 1000 * 1000; + +export function ConfirmLargeRequestBody({ children, request }: Props) { + const [showLargeResponse, toggleShowLargeResponse] = useToggle(); + + if (request.body?.text == null) { + return children; + } + + const contentLength = request.body.text.length ?? 0; + const tooLargeBytes = LARGE_TEXT_BYTES; + const isLarge = contentLength > tooLargeBytes; + if (!showLargeResponse && isLarge) { + return ( + +

+ Rendering content over{' '} + + + {' '} + may impact performance. +

+

+ See{' '} + + Working With Large Values + {' '} + for tips. +

+ + + + +
+ ); + } + + return <>{children}; +} diff --git a/src-web/components/HttpRequestPane.tsx b/src-web/components/HttpRequestPane.tsx index eedab5da..334382d8 100644 --- a/src-web/components/HttpRequestPane.tsx +++ b/src-web/components/HttpRequestPane.tsx @@ -35,6 +35,7 @@ import { prepareImportQuerystring } from '../lib/prepareImportQuerystring'; import { resolvedModelName } from '../lib/resolvedModelName'; import { showToast } from '../lib/toast'; import { BinaryFileEditor } from './BinaryFileEditor'; +import { ConfirmLargeRequestBody } from './ConfirmLargeRequestBody'; import { CountBadge } from './core/CountBadge'; import { Editor } from './core/Editor/Editor'; import type { GenericCompletionConfig } from './core/Editor/genericCompletion'; @@ -373,72 +374,74 @@ export function HttpRequestPane({ style, fullHeight, className, activeRequest }: /> - {activeRequest.bodyType === BODY_TYPE_JSON ? ( - - ) : activeRequest.bodyType === BODY_TYPE_XML ? ( - - ) : activeRequest.bodyType === BODY_TYPE_GRAPHQL ? ( - - ) : activeRequest.bodyType === BODY_TYPE_FORM_URLENCODED ? ( - - ) : activeRequest.bodyType === BODY_TYPE_FORM_MULTIPART ? ( - - ) : activeRequest.bodyType === BODY_TYPE_BINARY ? ( - patchModel(activeRequest, { body })} - onChangeContentType={handleContentTypeChange} - /> - ) : typeof activeRequest.bodyType === 'string' ? ( - - ) : ( - No Body - )} + + {activeRequest.bodyType === BODY_TYPE_JSON ? ( + + ) : activeRequest.bodyType === BODY_TYPE_XML ? ( + + ) : activeRequest.bodyType === BODY_TYPE_GRAPHQL ? ( + + ) : activeRequest.bodyType === BODY_TYPE_FORM_URLENCODED ? ( + + ) : activeRequest.bodyType === BODY_TYPE_FORM_MULTIPART ? ( + + ) : activeRequest.bodyType === BODY_TYPE_BINARY ? ( + patchModel(activeRequest, { body })} + onChangeContentType={handleContentTypeChange} + /> + ) : typeof activeRequest.bodyType === 'string' ? ( + + ) : ( + No Body + )} +