From 7d40e85e64762db8d420a33ed352f707edd7a9ba Mon Sep 17 00:00:00 2001
From: Emiliano Ciavatta
Date: Sat, 3 Oct 2020 00:13:53 +0200
Subject: Add json viewer feature
---
frontend/src/components/ConnectionContent.js | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
(limited to 'frontend/src/components/ConnectionContent.js')
diff --git a/frontend/src/components/ConnectionContent.js b/frontend/src/components/ConnectionContent.js
index 8667886..11b8617 100644
--- a/frontend/src/components/ConnectionContent.js
+++ b/frontend/src/components/ConnectionContent.js
@@ -6,6 +6,8 @@ import backend from "../backend";
import ButtonField from "./fields/ButtonField";
import ChoiceField from "./fields/ChoiceField";
import DOMPurify from 'dompurify';
+import ReactJson from 'react-json-view'
+import {getHeaderValue} from "../utils";
const classNames = require('classnames');
@@ -83,10 +85,21 @@ class ConnectionContent extends Component {
{unrollMap(m.trailers)}
;
case "http-response":
+ const contentType = getHeaderValue(m, "Content-Type");
+ let body = m.body;
+ if (contentType && contentType.includes("application/json")) {
+ try {
+ const json = JSON.parse(m.body);
+ body = ;
+ } catch (e) {
+ console.log(e);
+ }
+ }
+
return
{m.protocol} {m.status}
{unrollMap(m.headers)}
- {m.body}
+ {body}
{unrollMap(m.trailers)}
;
default:
@@ -114,7 +127,9 @@ class ConnectionContent extends Component {
}} />
);
case "http-response":
- if (m.headers && m.headers["Content-Type"].includes("text/html")) {
+ const contentType = getHeaderValue(m, "Content-Type");
+
+ if (contentType && contentType.includes("text/html")) {
return {
let w;
if (this.state.renderWindow && !this.state.renderWindow.closed) {
--
cgit v1.2.3-70-g09d2