mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-31 18:17:29 +00:00
Show gRPC as ASCII (#31)
* Moved try-catch up one block. * Display grpc as ASCII.
This commit is contained in:
@@ -69,19 +69,23 @@ export const HAREntryBodySection: React.FC<HAREntryBodySectionProps> = ({
|
||||
}) => {
|
||||
const MAXIMUM_BYTES_TO_HIGHLIGHT = 10000; // The maximum of chars to highlight in body, in case the response can be megabytes
|
||||
const supportedLanguages = [['html', 'html'], ['json', 'json'], ['application/grpc', 'json']]; // [[indicator, languageToUse],...]
|
||||
const jsonLikeFormats = ['json', 'application/grpc'];
|
||||
const jsonLikeFormats = ['json'];
|
||||
const binaryFormats = ['application/grpc'];
|
||||
const [isWrapped, setIsWrapped] = useState(false);
|
||||
|
||||
const formatTextBody = (body): string => {
|
||||
const chunk = body.slice(0, MAXIMUM_BYTES_TO_HIGHLIGHT);
|
||||
const bodyBuf = encoding === 'base64' ? atob(chunk) : chunk;
|
||||
|
||||
if (jsonLikeFormats.some(format => content?.mimeType?.indexOf(format) > -1)) {
|
||||
try {
|
||||
try {
|
||||
if (jsonLikeFormats.some(format => content?.mimeType?.indexOf(format) > -1)) {
|
||||
return JSON.stringify(JSON.parse(bodyBuf), null, 2);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} else if (binaryFormats.some(format => content?.mimeType?.indexOf(format) > -1)) {
|
||||
// Replace all non printable characters (ASCII)
|
||||
return atob(bodyBuf).replace(/[^ -~]/g, '.')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
return bodyBuf;
|
||||
}
|
||||
|
Reference in New Issue
Block a user