Fixed loading of request bodies
This commit is contained in:
@@ -77,6 +77,24 @@ function showHeadersHistory(element){
|
|||||||
showPopup();
|
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) {
|
async function formatXML(xml) {
|
||||||
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8082 + "/prettify";
|
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8082 + "/prettify";
|
||||||
var data = {
|
var data = {
|
||||||
@@ -103,29 +121,13 @@ async function formatXML(xml) {
|
|||||||
|
|
||||||
function showRequestBody(element){
|
function showRequestBody(element){
|
||||||
requestBody = "";
|
requestBody = "";
|
||||||
historyRequestBody = historyJson[element.id].requestBody;
|
var historyRequestBody = historyJson[element.id].requestBody;
|
||||||
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"
|
formatJSON(historyRequestBody).then(function(result) {
|
||||||
fetch(address, {
|
document.getElementById('code-highlight-content').innerText = result.data;
|
||||||
method: 'POST',
|
console.log(result.data);
|
||||||
body: historyRequestBody
|
highlightSyntax('code-highlight-content');
|
||||||
})
|
|
||||||
.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);
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -146,7 +148,7 @@ function showRequestBody(element){
|
|||||||
}
|
}
|
||||||
default:{
|
default:{
|
||||||
document.getElementById('code-highlight-content').innerText = historyRequestBody;
|
document.getElementById('code-highlight-content').innerText = historyRequestBody;
|
||||||
hljs.highlightElement(document.getElementById('history-request-body-content'));
|
highlightSyntax('code-highlight-content');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switchPopups('history-request-body');
|
switchPopups('history-request-body');
|
||||||
|
|||||||
Reference in New Issue
Block a user