import React, {Component} from 'react'; import './ConnectionContent.scss'; import {Button, Dropdown, Row} from 'react-bootstrap'; import MessageAction from "./MessageAction"; import backend from "../backend"; const classNames = require('classnames'); class ConnectionContent extends Component { constructor(props) { super(props); this.state = { loading: false, connectionContent: null, format: "default", tryParse: true, messageActionDialog: null }; this.validFormats = ["default", "hex", "hexdump", "base32", "base64", "ascii", "binary", "decimal", "octal"]; this.setFormat = this.setFormat.bind(this); } componentDidUpdate(prevProps, prevState, snapshot) { if (this.props.connection !== null && ( this.props.connection !== prevProps.connection || this.state.format !== prevState.format)) { this.setState({loading: true}); // TODO: limit workaround. backend.get(`/api/streams/${this.props.connection.id}?format=${this.state.format}&limit=999999`).then(res => { this.setState({ connectionContent: res, loading: false }); }); } } setFormat(format) { if (this.validFormats.includes(format)) { this.setState({format: format}); } } tryParseConnectionMessage(connectionMessage) { if (connectionMessage.metadata == null) { return connectionMessage.content; } if (connectionMessage["is_metadata_continuation"]) { return **already parsed in previous messages**; } let unrollMap = (obj) => obj == null ? null : Object.entries(obj).map(([key, value]) =>

{key}: {value}

); let m = connectionMessage.metadata; switch (m.type) { case "http-request": let url = {m.host}{m.url}; return

{m.method} {url} {m.protocol}

{unrollMap(m.headers)}
{m.body}
{unrollMap(m.trailers)}
; case "http-response": return

{m.protocol} {m.status}

{unrollMap(m.headers)}
{m.body}
{unrollMap(m.trailers)}
; default: return connectionMessage.content; } } connectionsActions(connectionMessage) { if (connectionMessage.metadata == null || connectionMessage.metadata["reproducers"] === undefined) { return null; } return Object.entries(connectionMessage.metadata["reproducers"]).map(([actionName, actionValue]) => ); } render() { let content = this.state.connectionContent; if (content == null) { return
select a connection to view
; } let payload = content.map((c, i) =>
offset: {c.index} | timestamp: {c.timestamp} | retransmitted: {c["is_retransmitted"] ? "yes" : "no"}
{this.connectionsActions(c)}
{c.from_client ? "client" : "server"}
{this.state.tryParse && this.state.format === "default" ? this.tryParseConnectionMessage(c) : c.content}
); return (
flow: {this.props.connection.ip_src}:{this.props.connection.port_src} -> {this.props.connection.ip_dst}:{this.props.connection.port_dst} | timestamp: {this.props.connection.started_at}
format plain hex hexdump base32 base64 ascii binary decimal octal view_as default download_as nl_separated only_client only_server
{payload}
{this.state.messageActionDialog}
); } } export default ConnectionContent;