Skip to content

Commit

Permalink
Merge pull request #276 from HuolalaTech/optimize/form-data-payload
Browse files Browse the repository at this point in the history
Optimize the network payload if meet the application/x-www-form-urlencoded
  • Loading branch information
wqcstrong authored Oct 22, 2024
2 parents d75cf22 + 0f349de commit a46836d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/components/NetworkTable/NetworkDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,24 @@ const TABS: TabItem[] = [
return !!requestPayload?.length || validEntries(getData);
},
content: (data) => {
const { getData, requestPayload } = data;
const { getData, requestPayload, requestHeader } = data;
const isFormUrlencoded = requestHeader?.some(([name, value]) => {
if (
name.toLowerCase() === 'content-type' &&
value.includes('application/x-www-form-urlencoded')
)
return true;
return false;
});

return (
<>
{/* Request Payload */}
{!!requestPayload?.length && (
<RequestPayloadBlock data={requestPayload} />
<RequestPayloadBlock
data={requestPayload}
urlencoded={isFormUrlencoded}
/>
)}

{/* Query String Parametes */}
Expand Down
9 changes: 7 additions & 2 deletions src/components/NetworkTable/RequestPayloadBlock/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import { EntriesBody } from '@/components/EntriesBody';

export const RequestPayloadBlock: React.FC<{
data: string | [string, string][];
}> = ({ data }) => {
urlencoded?: boolean;
}> = ({ data, urlencoded = false }) => {
const content = useMemo(() => {
if (isString(data)) {
if (urlencoded) {
const params = new URLSearchParams(data);
return <EntriesBody data={[...params]} />;
}
return <ReactJsonView source={data} defaultExpand />;
}
return <EntriesBody data={data} />;
}, [data]);
}, [data, urlencoded]);
return (
<div className="detail-block">
<b className="detail-block__label">Request Payload</b>
Expand Down

0 comments on commit a46836d

Please sign in to comment.