@rozenite/network-activity-plugin 1.0.0-alpha.11 → 1.0.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/App.html +2 -2
- package/dist/assets/{App-Ct73Yrm6.css → App-DCuHdq4D.css} +17 -0
- package/dist/assets/{App-BKBLGSeM.js → App-JuOeT_VQ.js} +2693 -2642
- package/dist/rozenite.json +1 -1
- package/dist/src/react-native/config.d.ts +13 -0
- package/dist/src/react-native/useNetworkActivityDevTools.d.ts +2 -1
- package/dist/src/shared/client.d.ts +15 -3
- package/dist/src/ui/components/Button.d.ts +1 -1
- package/dist/src/ui/components/CodeBlock.d.ts +3 -0
- package/dist/src/ui/components/CookieCard.d.ts +7 -0
- package/dist/src/ui/components/JsonTreeCopyableItem.d.ts +1 -1
- package/dist/src/ui/components/Section.d.ts +2 -1
- package/dist/src/ui/state/model.d.ts +4 -4
- package/dist/src/utils/applyReactNativeResponseHeadersLogic.d.ts +10 -0
- package/dist/src/utils/cookieParser.d.ts +6 -0
- package/dist/src/utils/getHttpHeader.d.ts +5 -0
- package/dist/src/utils/getStringSizeInBytes.d.ts +1 -0
- package/dist/src/utils/isNumber.d.ts +1 -0
- package/dist/useNetworkActivityDevTools.cjs +115 -19
- package/dist/useNetworkActivityDevTools.js +116 -20
- package/package.json +4 -4
- package/src/react-native/config.ts +33 -0
- package/src/react-native/http/network-inspector.ts +36 -10
- package/src/react-native/sse/sse-inspector.ts +1 -0
- package/src/react-native/useNetworkActivityDevTools.ts +63 -8
- package/src/shared/client.ts +17 -3
- package/src/ui/components/CodeBlock.tsx +19 -0
- package/src/ui/components/CookieCard.tsx +64 -0
- package/src/ui/components/JsonTree.tsx +10 -3
- package/src/ui/components/JsonTreeCopyableItem.tsx +14 -10
- package/src/ui/components/RequestList.tsx +15 -5
- package/src/ui/components/Section.tsx +31 -4
- package/src/ui/state/model.ts +4 -4
- package/src/ui/tabs/CookiesTab.tsx +64 -263
- package/src/ui/tabs/HeadersTab.tsx +26 -20
- package/src/ui/tabs/RequestTab.tsx +62 -47
- package/src/ui/tabs/ResponseTab.tsx +54 -69
- package/src/utils/applyReactNativeRequestHeadersLogic.ts +2 -2
- package/src/utils/applyReactNativeResponseHeadersLogic.ts +29 -0
- package/src/utils/cookieParser.ts +126 -0
- package/src/utils/getContentTypeMimeType.ts +10 -5
- package/src/utils/getHttpHeader.ts +17 -0
- package/src/utils/getStringSizeInBytes.ts +3 -0
- package/src/utils/isNumber.ts +3 -0
- package/src/utils/safeStringify.ts +1 -1
- package/dist/src/utils/getHttpHeaderValue.d.ts +0 -2
- package/src/utils/getHttpHeaderValue.ts +0 -14
|
@@ -1,278 +1,79 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import { ScrollArea } from '../components/ScrollArea';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
3
|
+
import { Section } from '../components/Section';
|
|
4
|
+
import { CookieCard } from '../components/CookieCard';
|
|
5
|
+
import {
|
|
6
|
+
parseRequestCookiesFromHeaders,
|
|
7
|
+
parseResponseCookiesFromHeaders,
|
|
8
|
+
} from '../../utils/cookieParser';
|
|
4
9
|
import { HttpNetworkEntry, SSENetworkEntry } from '../state/model';
|
|
5
10
|
|
|
6
|
-
type Cookie = {
|
|
7
|
-
name: string;
|
|
8
|
-
value: string;
|
|
9
|
-
domain?: string;
|
|
10
|
-
path?: string;
|
|
11
|
-
expires?: string;
|
|
12
|
-
maxAge?: string;
|
|
13
|
-
secure?: boolean;
|
|
14
|
-
httpOnly?: boolean;
|
|
15
|
-
sameSite?: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
11
|
export type CookiesTabProps = {
|
|
19
12
|
selectedRequest: HttpNetworkEntry | SSENetworkEntry;
|
|
20
13
|
};
|
|
21
14
|
|
|
22
|
-
const parseCookieString = (cookieString: string): Cookie[] => {
|
|
23
|
-
if (!cookieString) return [];
|
|
24
|
-
|
|
25
|
-
return cookieString
|
|
26
|
-
.split(';')
|
|
27
|
-
.map((cookieStr) => {
|
|
28
|
-
const [nameValue, ...attributes] = cookieStr.trim().split(';');
|
|
29
|
-
const [name, value] = nameValue.split('=');
|
|
30
|
-
|
|
31
|
-
const cookieObj: Cookie = {
|
|
32
|
-
name: name?.trim() || '',
|
|
33
|
-
value: value?.trim() || '',
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
// Parse attributes
|
|
37
|
-
attributes.forEach((attr) => {
|
|
38
|
-
const [attrName, attrValue] = attr.trim().split('=');
|
|
39
|
-
const lowerAttrName = attrName.toLowerCase();
|
|
40
|
-
|
|
41
|
-
switch (lowerAttrName) {
|
|
42
|
-
case 'domain':
|
|
43
|
-
cookieObj.domain = attrValue;
|
|
44
|
-
break;
|
|
45
|
-
case 'path':
|
|
46
|
-
cookieObj.path = attrValue;
|
|
47
|
-
break;
|
|
48
|
-
case 'expires':
|
|
49
|
-
cookieObj.expires = attrValue;
|
|
50
|
-
break;
|
|
51
|
-
case 'max-age':
|
|
52
|
-
cookieObj.maxAge = attrValue;
|
|
53
|
-
break;
|
|
54
|
-
case 'secure':
|
|
55
|
-
cookieObj.secure = true;
|
|
56
|
-
break;
|
|
57
|
-
case 'httponly':
|
|
58
|
-
cookieObj.httpOnly = true;
|
|
59
|
-
break;
|
|
60
|
-
case 'samesite':
|
|
61
|
-
cookieObj.sameSite = attrValue;
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
return cookieObj;
|
|
67
|
-
})
|
|
68
|
-
.filter((cookieObj) => cookieObj.name); // Filter out empty cookies
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const extractCookiesFromHeaders = (
|
|
72
|
-
headers: HttpHeaders
|
|
73
|
-
): {
|
|
74
|
-
requestCookies: Cookie[];
|
|
75
|
-
responseCookies: Cookie[];
|
|
76
|
-
} => {
|
|
77
|
-
const requestCookies: Cookie[] = [];
|
|
78
|
-
const responseCookies: Cookie[] = [];
|
|
79
|
-
|
|
80
|
-
Object.entries(headers).forEach(([key, value]) => {
|
|
81
|
-
const lowerKey = key.toLowerCase();
|
|
82
|
-
|
|
83
|
-
if (lowerKey === 'cookie') {
|
|
84
|
-
// Cookie header contains all cookies in one string
|
|
85
|
-
requestCookies.push(...parseCookieString(value));
|
|
86
|
-
} else if (lowerKey === 'set-cookie') {
|
|
87
|
-
// Set-Cookie header contains one cookie with attributes
|
|
88
|
-
const cookies = parseCookieString(value);
|
|
89
|
-
responseCookies.push(...cookies);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
return { requestCookies, responseCookies };
|
|
94
|
-
};
|
|
95
|
-
|
|
96
15
|
export const CookiesTab = ({ selectedRequest }: CookiesTabProps) => {
|
|
16
|
+
const requestHeaders = selectedRequest.request?.headers;
|
|
17
|
+
const responseHeaders = selectedRequest.response?.headers;
|
|
18
|
+
|
|
19
|
+
const { requestCookies, responseCookies } = React.useMemo(() => {
|
|
20
|
+
return {
|
|
21
|
+
requestCookies: parseRequestCookiesFromHeaders(requestHeaders || {}),
|
|
22
|
+
responseCookies: parseResponseCookiesFromHeaders(responseHeaders || {}),
|
|
23
|
+
};
|
|
24
|
+
}, [requestHeaders, responseHeaders]);
|
|
25
|
+
|
|
26
|
+
const hasRequestCookies = requestCookies.length > 0;
|
|
27
|
+
const hasResponseCookies = responseCookies.length > 0;
|
|
28
|
+
|
|
29
|
+
if (!hasRequestCookies && !hasResponseCookies) {
|
|
30
|
+
return (
|
|
31
|
+
<ScrollArea className="h-full w-full">
|
|
32
|
+
<div className="p-4">
|
|
33
|
+
<div className="text-sm text-gray-400">
|
|
34
|
+
No cookies for this request
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
</ScrollArea>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
97
41
|
return (
|
|
98
42
|
<ScrollArea className="h-full w-full">
|
|
99
43
|
<div className="p-4">
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return (
|
|
114
|
-
<div className="text-sm text-gray-400">
|
|
115
|
-
No cookies for this request
|
|
44
|
+
<div className="space-y-6">
|
|
45
|
+
{hasRequestCookies && (
|
|
46
|
+
<Section
|
|
47
|
+
title={`Request Cookies (${requestCookies.length})`}
|
|
48
|
+
>
|
|
49
|
+
<div className="space-y-2">
|
|
50
|
+
{requestCookies.map((cookie, index) => (
|
|
51
|
+
<CookieCard
|
|
52
|
+
key={`request-${index}`}
|
|
53
|
+
cookie={cookie}
|
|
54
|
+
keyClassName="text-blue-400"
|
|
55
|
+
/>
|
|
56
|
+
))}
|
|
116
57
|
</div>
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
<
|
|
122
|
-
{
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
{cookie.name}
|
|
137
|
-
</span>
|
|
138
|
-
<div className="flex items-center gap-2">
|
|
139
|
-
{cookie.secure && (
|
|
140
|
-
<Badge
|
|
141
|
-
variant="outline"
|
|
142
|
-
className="text-xs text-yellow-400 border-yellow-400"
|
|
143
|
-
>
|
|
144
|
-
Secure
|
|
145
|
-
</Badge>
|
|
146
|
-
)}
|
|
147
|
-
{cookie.httpOnly && (
|
|
148
|
-
<Badge
|
|
149
|
-
variant="outline"
|
|
150
|
-
className="text-xs text-purple-400 border-purple-400"
|
|
151
|
-
>
|
|
152
|
-
HttpOnly
|
|
153
|
-
</Badge>
|
|
154
|
-
)}
|
|
155
|
-
</div>
|
|
156
|
-
</div>
|
|
157
|
-
<div className="text-sm text-gray-300 mb-2">
|
|
158
|
-
{cookie.value}
|
|
159
|
-
</div>
|
|
160
|
-
<div className="grid grid-cols-2 gap-4 text-xs text-gray-400">
|
|
161
|
-
{cookie.domain && (
|
|
162
|
-
<div>
|
|
163
|
-
<span className="font-medium">Domain:</span>{' '}
|
|
164
|
-
{cookie.domain}
|
|
165
|
-
</div>
|
|
166
|
-
)}
|
|
167
|
-
{cookie.path && (
|
|
168
|
-
<div>
|
|
169
|
-
<span className="font-medium">Path:</span>{' '}
|
|
170
|
-
{cookie.path}
|
|
171
|
-
</div>
|
|
172
|
-
)}
|
|
173
|
-
{cookie.expires && (
|
|
174
|
-
<div>
|
|
175
|
-
<span className="font-medium">Expires:</span>{' '}
|
|
176
|
-
{cookie.expires}
|
|
177
|
-
</div>
|
|
178
|
-
)}
|
|
179
|
-
{cookie.maxAge && (
|
|
180
|
-
<div>
|
|
181
|
-
<span className="font-medium">Max-Age:</span>{' '}
|
|
182
|
-
{cookie.maxAge}
|
|
183
|
-
</div>
|
|
184
|
-
)}
|
|
185
|
-
{cookie.sameSite && (
|
|
186
|
-
<div>
|
|
187
|
-
<span className="font-medium">SameSite:</span>{' '}
|
|
188
|
-
{cookie.sameSite}
|
|
189
|
-
</div>
|
|
190
|
-
)}
|
|
191
|
-
</div>
|
|
192
|
-
</div>
|
|
193
|
-
))}
|
|
194
|
-
</div>
|
|
195
|
-
</div>
|
|
196
|
-
)}
|
|
197
|
-
|
|
198
|
-
{/* Response Cookies */}
|
|
199
|
-
{hasResponseCookies && (
|
|
200
|
-
<div>
|
|
201
|
-
<h4 className="text-sm font-medium text-gray-300 mb-3">
|
|
202
|
-
Response Cookies ({responseCookies.length})
|
|
203
|
-
</h4>
|
|
204
|
-
<div className="space-y-2">
|
|
205
|
-
{responseCookies.map((cookie, index) => (
|
|
206
|
-
<div
|
|
207
|
-
key={`response-${index}`}
|
|
208
|
-
className="bg-gray-800 border border-gray-700 rounded p-3"
|
|
209
|
-
>
|
|
210
|
-
<div className="flex items-center justify-between mb-2">
|
|
211
|
-
<span className="text-sm font-medium text-green-400">
|
|
212
|
-
{cookie.name}
|
|
213
|
-
</span>
|
|
214
|
-
<div className="flex items-center gap-2">
|
|
215
|
-
{cookie.secure && (
|
|
216
|
-
<Badge
|
|
217
|
-
variant="outline"
|
|
218
|
-
className="text-xs text-yellow-400 border-yellow-400"
|
|
219
|
-
>
|
|
220
|
-
Secure
|
|
221
|
-
</Badge>
|
|
222
|
-
)}
|
|
223
|
-
{cookie.httpOnly && (
|
|
224
|
-
<Badge
|
|
225
|
-
variant="outline"
|
|
226
|
-
className="text-xs text-purple-400 border-purple-400"
|
|
227
|
-
>
|
|
228
|
-
HttpOnly
|
|
229
|
-
</Badge>
|
|
230
|
-
)}
|
|
231
|
-
</div>
|
|
232
|
-
</div>
|
|
233
|
-
<div className="text-sm text-gray-300 mb-2">
|
|
234
|
-
{cookie.value}
|
|
235
|
-
</div>
|
|
236
|
-
<div className="grid grid-cols-2 gap-4 text-xs text-gray-400">
|
|
237
|
-
{cookie.domain && (
|
|
238
|
-
<div>
|
|
239
|
-
<span className="font-medium">Domain:</span>{' '}
|
|
240
|
-
{cookie.domain}
|
|
241
|
-
</div>
|
|
242
|
-
)}
|
|
243
|
-
{cookie.path && (
|
|
244
|
-
<div>
|
|
245
|
-
<span className="font-medium">Path:</span>{' '}
|
|
246
|
-
{cookie.path}
|
|
247
|
-
</div>
|
|
248
|
-
)}
|
|
249
|
-
{cookie.expires && (
|
|
250
|
-
<div>
|
|
251
|
-
<span className="font-medium">Expires:</span>{' '}
|
|
252
|
-
{cookie.expires}
|
|
253
|
-
</div>
|
|
254
|
-
)}
|
|
255
|
-
{cookie.maxAge && (
|
|
256
|
-
<div>
|
|
257
|
-
<span className="font-medium">Max-Age:</span>{' '}
|
|
258
|
-
{cookie.maxAge}
|
|
259
|
-
</div>
|
|
260
|
-
)}
|
|
261
|
-
{cookie.sameSite && (
|
|
262
|
-
<div>
|
|
263
|
-
<span className="font-medium">SameSite:</span>{' '}
|
|
264
|
-
{cookie.sameSite}
|
|
265
|
-
</div>
|
|
266
|
-
)}
|
|
267
|
-
</div>
|
|
268
|
-
</div>
|
|
269
|
-
))}
|
|
270
|
-
</div>
|
|
271
|
-
</div>
|
|
272
|
-
)}
|
|
273
|
-
</div>
|
|
274
|
-
);
|
|
275
|
-
})()}
|
|
58
|
+
</Section>
|
|
59
|
+
)}
|
|
60
|
+
|
|
61
|
+
{hasResponseCookies && (
|
|
62
|
+
<Section
|
|
63
|
+
title={`Response Cookies (${responseCookies.length})`}
|
|
64
|
+
>
|
|
65
|
+
<div className="space-y-2">
|
|
66
|
+
{responseCookies.map((cookie, index) => (
|
|
67
|
+
<CookieCard
|
|
68
|
+
key={`response-${index}`}
|
|
69
|
+
cookie={cookie}
|
|
70
|
+
keyClassName="text-green-400"
|
|
71
|
+
/>
|
|
72
|
+
))}
|
|
73
|
+
</div>
|
|
74
|
+
</Section>
|
|
75
|
+
)}
|
|
76
|
+
</div>
|
|
276
77
|
</div>
|
|
277
78
|
</ScrollArea>
|
|
278
79
|
);
|
|
@@ -5,11 +5,28 @@ import { KeyValueGrid, KeyValueItem } from '../components/KeyValueGrid';
|
|
|
5
5
|
import { HttpNetworkEntry, SSENetworkEntry } from '../state/model';
|
|
6
6
|
import { getStatusColor } from '../utils/getStatusColor';
|
|
7
7
|
import { CopyAsCurlButton } from '../components/CopyAsCurlButton';
|
|
8
|
+
import { HttpHeaders } from '../../shared/client';
|
|
8
9
|
|
|
9
10
|
export type HeadersTabProps = {
|
|
10
11
|
selectedRequest: HttpNetworkEntry | SSENetworkEntry;
|
|
11
12
|
};
|
|
12
13
|
|
|
14
|
+
function getHeadersItems(headers?: HttpHeaders): KeyValueItem[] {
|
|
15
|
+
if (!headers) return [];
|
|
16
|
+
|
|
17
|
+
return Object.entries(headers).reduce<KeyValueItem[]>((acc, [key, value]) => {
|
|
18
|
+
if (Array.isArray(value)) {
|
|
19
|
+
acc.push(
|
|
20
|
+
...value.map((item) => ({ key: key.toLowerCase(), value: item }))
|
|
21
|
+
);
|
|
22
|
+
} else {
|
|
23
|
+
acc.push({ key: key.toLowerCase(), value: value });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return acc;
|
|
27
|
+
}, []);
|
|
28
|
+
}
|
|
29
|
+
|
|
13
30
|
export const HeadersTab = ({ selectedRequest }: HeadersTabProps) => {
|
|
14
31
|
const requestBody = selectedRequest.request.body;
|
|
15
32
|
|
|
@@ -42,27 +59,15 @@ export const HeadersTab = ({ selectedRequest }: HeadersTabProps) => {
|
|
|
42
59
|
[selectedRequest]
|
|
43
60
|
);
|
|
44
61
|
|
|
45
|
-
const responseHeadersItems
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return Object.entries(headers).map(([key, value]) => ({
|
|
51
|
-
key: key.toLowerCase(),
|
|
52
|
-
value,
|
|
53
|
-
}));
|
|
54
|
-
}, [selectedRequest.response?.headers]);
|
|
55
|
-
|
|
56
|
-
const requestHeadersItems: KeyValueItem[] = useMemo(() => {
|
|
57
|
-
const headers = selectedRequest.request.headers;
|
|
58
|
-
|
|
59
|
-
if (!headers) return [];
|
|
62
|
+
const responseHeadersItems = useMemo(
|
|
63
|
+
() => getHeadersItems(selectedRequest.response?.headers),
|
|
64
|
+
[selectedRequest]
|
|
65
|
+
);
|
|
60
66
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}, [selectedRequest.request.headers]);
|
|
67
|
+
const requestHeadersItems = useMemo(
|
|
68
|
+
() => getHeadersItems(selectedRequest.request.headers),
|
|
69
|
+
[selectedRequest]
|
|
70
|
+
);
|
|
66
71
|
|
|
67
72
|
const isCopyAsCurlEnabled =
|
|
68
73
|
selectedRequest.request.body?.data.type !== 'binary';
|
|
@@ -73,6 +78,7 @@ export const HeadersTab = ({ selectedRequest }: HeadersTabProps) => {
|
|
|
73
78
|
{isCopyAsCurlEnabled && (
|
|
74
79
|
<CopyAsCurlButton selectedRequest={selectedRequest} />
|
|
75
80
|
)}
|
|
81
|
+
|
|
76
82
|
<Section title="General">
|
|
77
83
|
<KeyValueGrid items={generalItems} />
|
|
78
84
|
</Section>
|
|
@@ -2,78 +2,93 @@ import * as React from 'react';
|
|
|
2
2
|
import { ScrollArea } from '../components/ScrollArea';
|
|
3
3
|
import { JsonTree } from '../components/JsonTree';
|
|
4
4
|
import { HttpNetworkEntry, SSENetworkEntry } from '../state/model';
|
|
5
|
-
import {
|
|
5
|
+
import { KeyValueGrid } from '../components/KeyValueGrid';
|
|
6
|
+
import { Section } from '../components/Section';
|
|
7
|
+
import { CodeBlock } from '../components/CodeBlock';
|
|
8
|
+
import { ReactNode, useMemo } from 'react';
|
|
6
9
|
|
|
7
10
|
export type RequestTabProps = {
|
|
8
11
|
selectedRequest: HttpNetworkEntry | SSENetworkEntry;
|
|
9
12
|
};
|
|
10
13
|
|
|
11
|
-
const requestDataContainerClasses =
|
|
12
|
-
'bg-gray-800 p-3 rounded border border-gray-700';
|
|
13
|
-
|
|
14
14
|
export const RequestTab = ({ selectedRequest }: RequestTabProps) => {
|
|
15
|
+
const queryParams = useMemo(() => {
|
|
16
|
+
const { searchParams } = new URL(selectedRequest.request.url);
|
|
17
|
+
|
|
18
|
+
return Array.from(searchParams.entries());
|
|
19
|
+
}, [selectedRequest.request.url]);
|
|
20
|
+
|
|
15
21
|
const requestBody = selectedRequest.request.body;
|
|
22
|
+
const hasQueryParams = queryParams.length > 0;
|
|
23
|
+
|
|
24
|
+
const renderQueryParams = () => {
|
|
25
|
+
if (hasQueryParams) {
|
|
26
|
+
return (
|
|
27
|
+
<Section title={`Query Parameters (${queryParams.length})`}>
|
|
28
|
+
<KeyValueGrid
|
|
29
|
+
items={queryParams.map(([key, value]) => ({
|
|
30
|
+
key,
|
|
31
|
+
value,
|
|
32
|
+
}))}
|
|
33
|
+
/>
|
|
34
|
+
</Section>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return null;
|
|
39
|
+
};
|
|
16
40
|
|
|
17
41
|
const renderRequestBody = () => {
|
|
18
|
-
|
|
42
|
+
if (!requestBody) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const { type, data } = requestBody;
|
|
47
|
+
const { type: dataType, value } = data;
|
|
19
48
|
|
|
20
|
-
|
|
49
|
+
let bodyContent: ReactNode = null;
|
|
21
50
|
|
|
22
|
-
if (
|
|
51
|
+
if (dataType === 'text') {
|
|
23
52
|
try {
|
|
24
53
|
const jsonData = JSON.parse(value);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
<JsonTree data={jsonData} />
|
|
28
|
-
</div>
|
|
29
|
-
);
|
|
54
|
+
|
|
55
|
+
bodyContent = <JsonTree data={jsonData} />;
|
|
30
56
|
} catch {
|
|
31
|
-
|
|
32
|
-
return (
|
|
33
|
-
<pre
|
|
34
|
-
className={`text-sm font-mono text-gray-300 whitespace-pre-wrap overflow-x-auto ${requestDataContainerClasses}`}
|
|
35
|
-
>
|
|
36
|
-
{value}
|
|
37
|
-
</pre>
|
|
38
|
-
);
|
|
57
|
+
bodyContent = value;
|
|
39
58
|
}
|
|
40
59
|
}
|
|
41
60
|
|
|
42
61
|
// Show JSON tree as a temporary solution for form-data and binary types
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
<div className={requestDataContainerClasses}>
|
|
46
|
-
<JsonTree data={value} />
|
|
47
|
-
</div>
|
|
48
|
-
);
|
|
62
|
+
if (dataType === 'form-data' || dataType === 'binary') {
|
|
63
|
+
bodyContent = <JsonTree data={value} />
|
|
49
64
|
}
|
|
50
65
|
|
|
51
|
-
return
|
|
66
|
+
return (
|
|
67
|
+
<Section title="Request Body">
|
|
68
|
+
<div className="space-y-4">
|
|
69
|
+
<KeyValueGrid
|
|
70
|
+
items={[
|
|
71
|
+
{
|
|
72
|
+
key: 'Content-Type',
|
|
73
|
+
value: type,
|
|
74
|
+
valueClassName: 'text-blue-400',
|
|
75
|
+
},
|
|
76
|
+
]}
|
|
77
|
+
/>
|
|
78
|
+
{bodyContent && <CodeBlock>{bodyContent}</CodeBlock>}
|
|
79
|
+
</div>
|
|
80
|
+
</Section>
|
|
81
|
+
);
|
|
52
82
|
};
|
|
53
83
|
|
|
54
84
|
return (
|
|
55
85
|
<ScrollArea className="h-full w-full">
|
|
56
|
-
<div className="p-4">
|
|
57
|
-
{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
<h4 className="text-sm font-medium text-gray-300 mb-2">
|
|
61
|
-
Request Body
|
|
62
|
-
</h4>
|
|
63
|
-
<div className="text-sm mb-2">
|
|
64
|
-
<span className="text-gray-400">Content-Type: </span>
|
|
65
|
-
<span className="text-blue-400">
|
|
66
|
-
{selectedRequest.request.body.type}
|
|
67
|
-
</span>
|
|
68
|
-
</div>
|
|
69
|
-
</div>
|
|
70
|
-
<div>{renderRequestBody()}</div>
|
|
71
|
-
</div>
|
|
72
|
-
) : (
|
|
86
|
+
<div className="p-4 space-y-4">
|
|
87
|
+
{renderQueryParams()}
|
|
88
|
+
{renderRequestBody()}
|
|
89
|
+
{!hasQueryParams && !requestBody && (
|
|
73
90
|
<div className="text-sm text-gray-400">
|
|
74
|
-
|
|
75
|
-
? "GET requests don't have a request body"
|
|
76
|
-
: 'No request body for this request'}
|
|
91
|
+
No request body or query params for this request
|
|
77
92
|
</div>
|
|
78
93
|
)}
|
|
79
94
|
</div>
|