diff --git a/httpdbg/__init__.py b/httpdbg/__init__.py index 238a5ec..b67e49e 100644 --- a/httpdbg/__init__.py +++ b/httpdbg/__init__.py @@ -1,4 +1,4 @@ -__version__ = "2.1.1" +__version__ = "2.1.2" __all__ = ["export_html", "httprecord", "HTTPRecords"] diff --git a/httpdbg/export.py b/httpdbg/export.py index 1631131..511b916 100644 --- a/httpdbg/export.py +++ b/httpdbg/export.py @@ -94,6 +94,7 @@ def safe_for_script_tag(s: str) -> str: global.static_requests = JSON.parse( document.getElementById('requests-map').textContent ); + global.connected = false; """ diff --git a/httpdbg/webapp/static/api.js b/httpdbg/webapp/static/api.js index ed26e18..70db6b4 100644 --- a/httpdbg/webapp/static/api.js +++ b/httpdbg/webapp/static/api.js @@ -50,10 +50,13 @@ function save_request(request_id, request, session_id) { } async function load_all_requests() { + // export mode if (typeof global.static_all_requests !== "undefined") { + global.connected = false; return global.static_all_requests; } + // connected mode var requests_already_loaded = 0 for (const [request_id, request] of Object.entries(global.requests)) { if (request.loaded && (global.session == request.session_id)) { @@ -65,95 +68,104 @@ async function load_all_requests() { "requests_already_loaded": requests_already_loaded, }) - const res = await fetch(url); - const data = await res.json(); - return data; + try { + const res = await fetch(url); + const data = await res.json(); + global.connected = true; + return data; + } catch (error) { + global.connected = false; + return null; + } } async function get_all_requests() { - await load_all_requests() - .then(data => { - global.connected = true; - - if (data.session.id != global.session) { - clean(); - global.session = data.session.id; - global.sessions[data.session.id] = data.session; - }; - - // for the initiators and the groups, we can just save them without any verification - Object.assign(global.initiators, data.initiators); - Object.assign(global.groups, data.groups); - - // for the requests, we may have to update them - for (const [request_id, request] of Object.entries(data.requests)) { - if (!(request_id in global.requests)) { - // this is a new request - save_request(request_id, request, data.session.id); - } else { - if (global.requests[request_id].last_update < request.last_update) { - // this request has been updated (probably a "big" file) - save_request(request_id, request, data.session.id); - } - }; - }; - }) - .catch((error) => { - global.connected = false; - }); + const data = await load_all_requests(); + + if (!data) { + return; + } + + if (data.session.id != global.session) { + clean(); + global.session = data.session.id; + global.sessions[data.session.id] = data.session; + }; + + // for the initiators and the groups, we can just save them without any verification + Object.assign(global.initiators, data.initiators); + Object.assign(global.groups, data.groups); + + // for the requests, we may have to update them + for (const [request_id, request] of Object.entries(data.requests)) { + if (!(request_id in global.requests)) { + // this is a new request + save_request(request_id, request, data.session.id); + } else { + if (global.requests[request_id].last_update < request.last_update) { + // this request has been updated (probably a "big" file) + save_request(request_id, request, data.session.id); + } + }; + }; } async function load_request(request_id) { if (typeof global.static_requests !== "undefined") { + global.connected = false; return global.static_requests[request_id]; } - const res = await fetch("/request/" + request_id); - const data = await res.json(); - return data; + try { + const res = await fetch("/request/" + request_id); + const data = await res.json(); + global.connected = true; + return data; + } catch (error) { + global.connected = false; + return null; + } } async function get_request(request_id) { - await load_request(request_id) - .then(data => { - global.connected = true; - global.requests[request_id].filter = prepare_for_filter(global.requests[request_id].url); - - global.requests[request_id].request = data.request; - if (data.request.body && data.request.body.text) { - global.requests[request_id].filter += " " + prepare_for_filter( - parse_raw_text( - data.request.body.text, - data.request.body.content_type - ) || data.request.body.text - ); - } + const data = await load_request(request_id); - global.requests[request_id].response = data.response; - if (data.response.body && data.response.body.text) { - global.requests[request_id].filter += " " + prepare_for_filter( - parse_raw_text( - data.response.body.text, - data.response.body.content_type - ) || data.response.body.text - ); - } + if (!data) { + return; + } + + global.requests[request_id].filter = prepare_for_filter(global.requests[request_id].url); - // the full stack is not present in request summary - global.requests[request_id].initiator_id = data.initiator_id; - global.requests[request_id].exception = data.exception; + global.requests[request_id].request = data.request; + if (data.request.body && data.request.body.text) { + global.requests[request_id].filter += " " + prepare_for_filter( + parse_raw_text( + data.request.body.text, + data.request.body.content_type + ) || data.request.body.text + ); + } + + global.requests[request_id].response = data.response; + if (data.response.body && data.response.body.text) { + global.requests[request_id].filter += " " + prepare_for_filter( + parse_raw_text( + data.response.body.text, + data.response.body.content_type + ) || data.response.body.text + ); + } - global.requests[request_id].to_refresh = true; + // the full stack is not present in request summary + global.requests[request_id].initiator_id = data.initiator_id; + global.requests[request_id].exception = data.exception; - global.requests[request_id].loaded = true; - }) - .catch((error) => { - global.connected = false; - }); + global.requests[request_id].to_refresh = true; + global.requests[request_id].loaded = true; } async function pol_new_data() { diff --git a/httpdbg/webapp/static/icons/information-mark-circle-outline-icon.svg b/httpdbg/webapp/static/icons/information-mark-circle-outline-icon.svg deleted file mode 100644 index 443f621..0000000 --- a/httpdbg/webapp/static/icons/information-mark-circle-outline-icon.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/httpdbg/webapp/static/index.htm b/httpdbg/webapp/static/index.htm index 982560f..a3f18ef 100644 --- a/httpdbg/webapp/static/index.htm +++ b/httpdbg/webapp/static/index.htm @@ -377,7 +377,6 @@

request cookies

{{#body}} {{#body.path}} - {{/body.path}} {{#body.text}} diff --git a/httpdbg/webapp/static/render.js b/httpdbg/webapp/static/render.js index 8e095f4..26cfad9 100644 --- a/httpdbg/webapp/static/render.js +++ b/httpdbg/webapp/static/render.js @@ -260,7 +260,6 @@ async function disable_link_if_server_disconnected() { if (global.connected) { sheet.insertRule(".need-server {}"); - sheet.insertRule(".need-server-info {display: none;}"); } else { sheet.insertRule(".need-server {\ color: var(--link-server-disconnected);\ @@ -268,11 +267,6 @@ async function disable_link_if_server_disconnected() { opacity: 0.5;\ text-decoration: none;\ }"); - sheet.insertRule(".need-server-info {\ - display: inline;\ - color: var(--link-server-disconnected);\ - opacity: 0.5;\ - }"); } }