aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/ConnectionContent.js
diff options
context:
space:
mode:
authorEmiliano Ciavatta2020-10-02 21:35:12 +0000
committerEmiliano Ciavatta2020-10-02 21:35:12 +0000
commitd3d13f101a45dace9ca7eb5291d3d51dfb315d84 (patch)
treea153a055df8bcd264ac732b99172e68ce8a1d07c /frontend/src/components/ConnectionContent.js
parent6204c99e69d1707a79c5e56685b47310106c60b0 (diff)
Add render_html feature
Diffstat (limited to 'frontend/src/components/ConnectionContent.js')
-rw-r--r--frontend/src/components/ConnectionContent.js67
1 files changed, 51 insertions, 16 deletions
diff --git a/frontend/src/components/ConnectionContent.js b/frontend/src/components/ConnectionContent.js
index ccaec0b..8667886 100644
--- a/frontend/src/components/ConnectionContent.js
+++ b/frontend/src/components/ConnectionContent.js
@@ -5,6 +5,7 @@ import MessageAction from "./MessageAction";
import backend from "../backend";
import ButtonField from "./fields/ButtonField";
import ChoiceField from "./fields/ChoiceField";
+import DOMPurify from 'dompurify';
const classNames = require('classnames');
@@ -21,7 +22,6 @@ class ConnectionContent extends Component {
};
this.validFormats = ["default", "hex", "hexdump", "base32", "base64", "ascii", "binary", "decimal", "octal"];
- this.setFormat = this.setFormat.bind(this);
}
componentDidMount() {
@@ -33,10 +33,15 @@ class ConnectionContent extends Component {
componentDidUpdate(prevProps, prevState, snapshot) {
if (this.props.connection != null && (
this.props.connection !== prevProps.connection || this.state.format !== prevState.format)) {
+ this.closeRenderWindow();
this.loadStream();
}
}
+ componentWillUnmount() {
+ this.closeRenderWindow();
+ }
+
loadStream = () => {
this.setState({loading: true});
// TODO: limit workaround.
@@ -48,13 +53,13 @@ class ConnectionContent extends Component {
});
};
- setFormat(format) {
+ setFormat = (format) => {
if (this.validFormats.includes(format)) {
this.setState({format: format});
}
- }
+ };
- tryParseConnectionMessage(connectionMessage) {
+ tryParseConnectionMessage = (connectionMessage) => {
if (connectionMessage.metadata == null) {
return connectionMessage.content;
}
@@ -87,22 +92,52 @@ class ConnectionContent extends Component {
default:
return connectionMessage.content;
}
- }
+ };
- connectionsActions(connectionMessage) {
- if (connectionMessage.metadata == null || connectionMessage.metadata["reproducers"] === undefined) {
+ connectionsActions = (connectionMessage) => {
+ if (connectionMessage.metadata == null) { //} || !connectionMessage.metadata["reproducers"]) {
return null;
}
- return Object.entries(connectionMessage.metadata["reproducers"]).map(([actionName, actionValue]) =>
- <ButtonField small key={actionName + "_button"} name={actionName} onClick={() => {
- this.setState({
- messageActionDialog: <MessageAction actionName={actionName} actionValue={actionValue}
- onHide={() => this.setState({messageActionDialog: null})}/>
- });
- }} />
- );
- }
+ const m = connectionMessage.metadata;
+ switch (m.type) {
+ case "http-request" :
+ if (!connectionMessage.metadata["reproducers"]) {
+ return;
+ }
+ return Object.entries(connectionMessage.metadata["reproducers"]).map(([actionName, actionValue]) =>
+ <ButtonField small key={actionName + "_button"} name={actionName} onClick={() => {
+ this.setState({
+ messageActionDialog: <MessageAction actionName={actionName} actionValue={actionValue}
+ onHide={() => this.setState({messageActionDialog: null})}/>
+ });
+ }} />
+ );
+ case "http-response":
+ if (m.headers && m.headers["Content-Type"].includes("text/html")) {
+ return <ButtonField small name="render_html" onClick={() => {
+ let w;
+ if (this.state.renderWindow && !this.state.renderWindow.closed) {
+ w = this.state.renderWindow;
+ } else {
+ w = window.open("", "", "width=900, height=600, scrollbars=yes");
+ this.setState({renderWindow: w});
+ }
+ w.document.body.innerHTML = DOMPurify.sanitize(m.body);
+ w.focus();
+ }} />;
+ }
+ break;
+ default:
+ return null;
+ }
+ };
+
+ closeRenderWindow = () => {
+ if (this.state.renderWindow) {
+ this.state.renderWindow.close();
+ }
+ };
render() {
let content = this.state.connectionContent;