import React from 'react' import Table from 'react-bootstrap/Table' import { Base64 } from 'js-base64' import './App.css' const isTextResponse = response => { if (!response) return false if (!response.header) return false if (!response.header['Content-Type']) return false return /text|javascript|json/.test(response.header['Content-Type'].join('')) } class App extends React.Component { constructor(props) { super(props) this.state = { flows: [], flow: null, flowTab: 'Headers', // Headers, Preview, Response } this.ws = null } componentDidMount() { this.initWs() } componentWillUnmount() { if (this.ws) { this.ws.close() } } initWs() { if (this.ws) return this.ws = new WebSocket("ws://localhost:9081/echo") this.ws.onopen = () => { console.log('OPEN') } this.ws.onclose = () => { console.log('CLOSE') } this.ws.onmessage = evt => { const data = JSON.parse(evt.data) console.log(data) const flow = data.flow const id = flow.id if (data.on === 'request') { this.setState({ flows: this.state.flows.concat(flow) }) } else if (data.on === 'response') { const flows = this.state.flows.map(f => { if (f.id === id) return flow return f }) this.setState({ flows }) } } this.ws.onerror = evt => { console.log('ERROR: ' + evt.data) } // this.ws.send('msg') // this.ws.close() } renderFlow() { const { flow, flowTab } = this.state if (!flow) return null const request = flow.request const response = flow.response || {} return (
General
Request URL: {request.url}
Request Method: {request.method}
Status Code: {`${response.statusCode || '(pending)'}`}
Response Headers
{key}: {response.header[key].join(' ')}
) }) }Request Headers
{key}: {request.header[key].join(' ')}
) }) }Host | Path | Method | Status |
---|---|---|---|
{u.host} | {path} | {request.method} | {response.statusCode || '(pending)'} |