/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @format */ import {Request, Response, Header, Insights, RetryInsights} from './types'; import { Component, FlexColumn, ManagedTable, ManagedDataInspector, Text, Panel, Select, styled, colors, } from 'flipper'; import {decodeBody, getHeaderValue} from './utils'; import {formatBytes} from './index'; import React from 'react'; import querystring from 'querystring'; import xmlBeautifier from 'xml-beautifier'; const WrappingText = styled(Text)({ wordWrap: 'break-word', width: '100%', lineHeight: '125%', padding: '3px 0', }); const KeyValueColumnSizes = { key: '30%', value: 'flex', }; const KeyValueColumns = { key: { value: 'Key', resizable: false, }, value: { value: 'Value', resizable: false, }, }; type RequestDetailsProps = { request: Request; response: Response | null | undefined; }; type RequestDetailsState = { bodyFormat: string; }; export default class RequestDetails extends Component< RequestDetailsProps, RequestDetailsState > { static Container = styled(FlexColumn)({ height: '100%', overflow: 'auto', }); static BodyOptions = { formatted: 'formatted', parsed: 'parsed', }; state: RequestDetailsState = {bodyFormat: RequestDetails.BodyOptions.parsed}; urlColumns = (url: URL) => { return [ { columns: { key: {value: Full URL}, value: { value: {url.href}, }, }, copyText: url.href, key: 'url', }, { columns: { key: {value: Host}, value: { value: {url.host}, }, }, copyText: url.host, key: 'host', }, { columns: { key: {value: Path}, value: { value: {url.pathname}, }, }, copyText: url.pathname, key: 'path', }, { columns: { key: {value: Query String}, value: { value: {url.search}, }, }, copyText: url.search, key: 'query', }, ]; }; onSelectFormat = (bodyFormat: string) => { this.setState(() => ({bodyFormat})); }; render() { const {request, response} = this.props; const url = new URL(request.url); const {bodyFormat} = this.state; const formattedText = bodyFormat == RequestDetails.BodyOptions.formatted; return ( {url.search ? ( ) : null} {request.headers.length > 0 ? ( ) : null} {request.data != null ? ( ) : null} {response ? ( <> {response.headers.length > 0 ? ( ) : null} ) : null}