XML request bodies are now formatted

This commit is contained in:
2023-05-18 15:05:28 +02:00
parent f25d8f0e7e
commit 92df5abf9c
2 changed files with 63 additions and 30 deletions

View File

@@ -77,10 +77,41 @@ function showHeadersHistory(element){
showPopup(); showPopup();
} }
function formatXML(xml) {
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8082 + "/prettify";
var data = {
data: xml,
process: "",
processor: "libxml",
version: "1.0"
}
console.log("formattedXML");
fetch(address, {
method: 'POST',
body: JSON.stringify(data)
})
.then(async (response) => {
const promise = response.json();
if (!response.ok) {
throw Error(await promise);
}
return promise;
})
.then((data) => {
document.getElementById('code-highlight-content').innerText = data.result;
highlightSyntax('code-highlight-content');
//console.log(data.result);
})
.catch((error) => {
console.error('Error:', error);
});
}
function showRequestBody(element){ function showRequestBody(element){
requestBody = ""; requestBody = "";
historyRequestBody = historyJson[element.id].requestBody; historyRequestBody = historyJson[element.id].requestBody;
console.log(historyRequestBody);
switch(historyJson[element.id].headers["content-type"]){ switch(historyJson[element.id].headers["content-type"]){
case "application/json":{ case "application/json":{
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/formatting" const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/formatting"
@@ -97,6 +128,7 @@ function showRequestBody(element){
}) })
.then((data) => { .then((data) => {
requestBody = '<code class="language=json">'+data.data+'</code>'; requestBody = '<code class="language=json">'+data.data+'</code>';
document.getElementById('history-request-body-content').innerHTML = requestBody; document.getElementById('history-request-body-content').innerHTML = requestBody;
hljs.highlightElement(document.getElementById('history-request-body-content')); hljs.highlightElement(document.getElementById('history-request-body-content'));
}) })
@@ -106,13 +138,14 @@ function showRequestBody(element){
break; break;
} }
case "application/xml":{ case "application/xml":{
document.getElementById('code-highlight-content').innerText = historyRequestBody; //document.getElementById('code-highlight-content').innerText = historyRequestBody;
highlightSyntax('code-highlight-content'); formatXML(historyRequestBody);
break; break;
} }
default:{ default:{
requestBody = '<code>'+historyRequestBody+'</code>' requestBody = '<code>'+historyRequestBody+'</code>';
document.getElementById('history-request-body-content').innerText = requestBody; document.getElementById('history-request-body-content').innerText = requestBody;
hljs.highlightElement(document.getElementById('history-request-body-content')); hljs.highlightElement(document.getElementById('history-request-body-content'));
} }

View File

@@ -9,36 +9,36 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head> </head>
<body> <body>
<div class="popup-flex hiddable-container"> <div class="popup-flex hiddable-container">
<div class="popup-body" id="popup-body"> <div class="popup-body" id="popup-body">
<div class="popup-button-close-container"> <div class="popup-button-close-container">
<button type="button" class="popup-button-close"> X </button> <button type="button" class="popup-button-close"> X </button>
</div> </div>
<div class="popup-header-table hiddable-popup-option" id="history-headers-table"> <div class="popup-header-table hiddable-popup-option" id="history-headers-table">
<table id="header-table"> <table id="header-table">
<thead> <thead>
<tr> <tr>
<th> <th>
Header Name Header Name
</th> </th>
<th> <th>
Header Value Header Value
</th> </th>
</tr> </tr>
</thead> </thead>
<tbody id="header-history-table-body"> <tbody id="header-history-table-body">
</tbody> </tbody>
</table> </table>
</div> </div>
<div class="popup-request-body hiddable-popup-option" id="history-request-body"> <div class="popup-request-body hiddable-popup-option" id="history-request-body">
<pre class="code-content" id="history-request-body-content"> <pre class="code-content" id="history-request-body-content">
<code id="code-highlight-content"></code> <code id="code-highlight-content"></code>
</pre> </pre>
</div>
</div> </div>
</div> </div>
</div>
<div class="container"> <div class="container">
<div class="tool extended"> <div class="tool extended">
<div class="tool-context"> <div class="tool-context">