Fixed loading of request bodies

This commit is contained in:
2023-05-18 15:45:11 +02:00
parent 081ce03d38
commit 80d3c708dd

View File

@@ -77,6 +77,24 @@ function showHeadersHistory(element){
showPopup();
}
async function formatJSON(json) {
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/formatting";
var init = {
body: json,
method: "POST"
};
var request = new Request(address, init);
var result = await fetch(request).then(response => {
return response.text().then(function (text) {
return JSON.parse(text);
});
});
return result;
}
async function formatXML(xml) {
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8082 + "/prettify";
var data = {
@@ -103,30 +121,14 @@ async function formatXML(xml) {
function showRequestBody(element){
requestBody = "";
historyRequestBody = historyJson[element.id].requestBody;
var historyRequestBody = historyJson[element.id].requestBody;
switch(historyJson[element.id].headers["content-type"]){
case "application/json":{
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/formatting"
fetch(address, {
method: 'POST',
body: historyRequestBody
})
.then(async (response) => {
const promise = response.json();
if (!response.ok) {
throw Error(await promise);
}
return promise;
})
.then((data) => {
requestBody = '<code class="language=json">'+data.data+'</code>';
document.getElementById('history-request-body-content').innerHTML = requestBody;
hljs.highlightElement(document.getElementById('history-request-body-content'));
})
.catch((error) => {
console.error('Error:', error);
});
formatJSON(historyRequestBody).then(function(result) {
document.getElementById('code-highlight-content').innerText = result.data;
console.log(result.data);
highlightSyntax('code-highlight-content');
});
break;
}
case "application/xml":{
@@ -146,7 +148,7 @@ function showRequestBody(element){
}
default:{
document.getElementById('code-highlight-content').innerText = historyRequestBody;
hljs.highlightElement(document.getElementById('history-request-body-content'));
highlightSyntax('code-highlight-content');
}
}
switchPopups('history-request-body');