import styles from "~components/Details/Details.module.scss"; import * as React from "react"; import classNames from "classnames"; import {RequestPayload, ResponsePayload} from "~hooks/useRequests"; import { Dispatch, forwardRef, SetStateAction, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react"; import ReactJson from 'react-json-view'; import styles from './Content.module.scss'; import {Col, Container, Row} from "react-bootstrap"; function getHeader(headers: { [key: string]: string }, key: string, unit?: string): string | null { console.log(headers, key) try { const [_, value] = Object .entries(headers) .find(([headerKey]) => headerKey.toLowerCase() === key.toLowerCase()) return unit !== undefined ? `${value}${unit}` : value } catch { return null; } } interface ContentProps { data: RequestPayload | ResponsePayload setRaw: Dispatch> raw?: boolean } export default function Content({ raw, setRaw, data }: ContentProps): JSX.Element { return ( <> setRaw(!raw)}/> { [ getHeader(data.headers, 'content-length', 'bytes'), getHeader(data.headers, 'content-type'), ].filter(x => x !== null).join('; ') } {(() => { try { return ContentBody({ data, raw }) } catch { return (

Body could not be rendered

setRaw(true)}>View raw
) } })()}
//
//
// setRaw(!raw)}/> // //
//
// {(() => { // try { // return ContentBody({ ...props, raw }) // } catch { // return ( //
//

Body could not be rendered

// setRaw(true)}>View raw //
// ) // } // })()} //
//
) }; function ContentBody({ data, raw = false }: Omit) { const contentType = useMemo(() => { if (raw) { return ''; } const type = getHeader(data.headers, 'content-type'); return type.toLowerCase().split(';')[0]; }, [data, raw]); if (raw) { return
{atob(data.body)}
} if (['application/pdf', 'text/html'].includes(contentType)) { return