Skip to content

Commit deb8d53

Browse files
authored
disable download in export mode (#211)
1 parent 61a5f99 commit deb8d53

File tree

6 files changed

+82
-77
lines changed

6 files changed

+82
-77
lines changed

httpdbg/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "2.1.1"
1+
__version__ = "2.1.2"
22

33
__all__ = ["export_html", "httprecord", "HTTPRecords"]
44

httpdbg/export.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def safe_for_script_tag(s: str) -> str:
9494
global.static_requests = JSON.parse(
9595
document.getElementById('requests-map').textContent
9696
);
97+
global.connected = false;
9798
</script>
9899
"""
99100

httpdbg/webapp/static/api.js

Lines changed: 80 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ function save_request(request_id, request, session_id) {
5050
}
5151

5252
async function load_all_requests() {
53+
// export mode
5354
if (typeof global.static_all_requests !== "undefined") {
55+
global.connected = false;
5456
return global.static_all_requests;
5557
}
5658

59+
// connected mode
5760
var requests_already_loaded = 0
5861
for (const [request_id, request] of Object.entries(global.requests)) {
5962
if (request.loaded && (global.session == request.session_id)) {
@@ -65,95 +68,104 @@ async function load_all_requests() {
6568
"requests_already_loaded": requests_already_loaded,
6669
})
6770

68-
const res = await fetch(url);
69-
const data = await res.json();
70-
return data;
71+
try {
72+
const res = await fetch(url);
73+
const data = await res.json();
74+
global.connected = true;
75+
return data;
76+
} catch (error) {
77+
global.connected = false;
78+
return null;
79+
}
7180
}
7281

7382

7483
async function get_all_requests() {
7584

76-
await load_all_requests()
77-
.then(data => {
78-
global.connected = true;
79-
80-
if (data.session.id != global.session) {
81-
clean();
82-
global.session = data.session.id;
83-
global.sessions[data.session.id] = data.session;
84-
};
85-
86-
// for the initiators and the groups, we can just save them without any verification
87-
Object.assign(global.initiators, data.initiators);
88-
Object.assign(global.groups, data.groups);
89-
90-
// for the requests, we may have to update them
91-
for (const [request_id, request] of Object.entries(data.requests)) {
92-
if (!(request_id in global.requests)) {
93-
// this is a new request
94-
save_request(request_id, request, data.session.id);
95-
} else {
96-
if (global.requests[request_id].last_update < request.last_update) {
97-
// this request has been updated (probably a "big" file)
98-
save_request(request_id, request, data.session.id);
99-
}
100-
};
101-
};
102-
})
103-
.catch((error) => {
104-
global.connected = false;
105-
});
85+
const data = await load_all_requests();
86+
87+
if (!data) {
88+
return;
89+
}
90+
91+
if (data.session.id != global.session) {
92+
clean();
93+
global.session = data.session.id;
94+
global.sessions[data.session.id] = data.session;
95+
};
96+
97+
// for the initiators and the groups, we can just save them without any verification
98+
Object.assign(global.initiators, data.initiators);
99+
Object.assign(global.groups, data.groups);
100+
101+
// for the requests, we may have to update them
102+
for (const [request_id, request] of Object.entries(data.requests)) {
103+
if (!(request_id in global.requests)) {
104+
// this is a new request
105+
save_request(request_id, request, data.session.id);
106+
} else {
107+
if (global.requests[request_id].last_update < request.last_update) {
108+
// this request has been updated (probably a "big" file)
109+
save_request(request_id, request, data.session.id);
110+
}
111+
};
112+
};
106113
}
107114

108115
async function load_request(request_id) {
109116
if (typeof global.static_requests !== "undefined") {
117+
global.connected = false;
110118
return global.static_requests[request_id];
111119
}
112120

113-
const res = await fetch("/request/" + request_id);
114-
const data = await res.json();
115-
return data;
121+
try {
122+
const res = await fetch("/request/" + request_id);
123+
const data = await res.json();
124+
global.connected = true;
125+
return data;
126+
} catch (error) {
127+
global.connected = false;
128+
return null;
129+
}
116130
}
117131

118132
async function get_request(request_id) {
119133

120-
await load_request(request_id)
121-
.then(data => {
122-
global.connected = true;
123-
global.requests[request_id].filter = prepare_for_filter(global.requests[request_id].url);
124-
125-
global.requests[request_id].request = data.request;
126-
if (data.request.body && data.request.body.text) {
127-
global.requests[request_id].filter += " " + prepare_for_filter(
128-
parse_raw_text(
129-
data.request.body.text,
130-
data.request.body.content_type
131-
) || data.request.body.text
132-
);
133-
}
134+
const data = await load_request(request_id);
134135

135-
global.requests[request_id].response = data.response;
136-
if (data.response.body && data.response.body.text) {
137-
global.requests[request_id].filter += " " + prepare_for_filter(
138-
parse_raw_text(
139-
data.response.body.text,
140-
data.response.body.content_type
141-
) || data.response.body.text
142-
);
143-
}
136+
if (!data) {
137+
return;
138+
}
139+
140+
global.requests[request_id].filter = prepare_for_filter(global.requests[request_id].url);
144141

145-
// the full stack is not present in request summary
146-
global.requests[request_id].initiator_id = data.initiator_id;
147-
global.requests[request_id].exception = data.exception;
142+
global.requests[request_id].request = data.request;
143+
if (data.request.body && data.request.body.text) {
144+
global.requests[request_id].filter += " " + prepare_for_filter(
145+
parse_raw_text(
146+
data.request.body.text,
147+
data.request.body.content_type
148+
) || data.request.body.text
149+
);
150+
}
151+
152+
global.requests[request_id].response = data.response;
153+
if (data.response.body && data.response.body.text) {
154+
global.requests[request_id].filter += " " + prepare_for_filter(
155+
parse_raw_text(
156+
data.response.body.text,
157+
data.response.body.content_type
158+
) || data.response.body.text
159+
);
160+
}
148161

149-
global.requests[request_id].to_refresh = true;
162+
// the full stack is not present in request summary
163+
global.requests[request_id].initiator_id = data.initiator_id;
164+
global.requests[request_id].exception = data.exception;
150165

151-
global.requests[request_id].loaded = true;
152-
})
153-
.catch((error) => {
154-
global.connected = false;
155-
});
166+
global.requests[request_id].to_refresh = true;
156167

168+
global.requests[request_id].loaded = true;
157169
}
158170

159171
async function pol_new_data() {

httpdbg/webapp/static/icons/information-mark-circle-outline-icon.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

httpdbg/webapp/static/index.htm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ <h4>request cookies</h4>
377377
{{#body}}
378378
{{#body.path}}
379379
<a href="{{body.path}}" download="{{body.filename}}" class="need-server"><button title="download"><svg class="icon"><use href="#download-install-line-icon"></use></svg></button></a>
380-
<svg class="icon need-server-info"><use href="#information-mark-circle-outline-icon"></use></svg>
381380
{{/body.path}}
382381

383382
{{#body.text}}

httpdbg/webapp/static/render.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,19 +260,13 @@ async function disable_link_if_server_disconnected() {
260260

261261
if (global.connected) {
262262
sheet.insertRule(".need-server {}");
263-
sheet.insertRule(".need-server-info {display: none;}");
264263
} else {
265264
sheet.insertRule(".need-server {\
266265
color: var(--link-server-disconnected);\
267266
pointer-events: none;\
268267
opacity: 0.5;\
269268
text-decoration: none;\
270269
}");
271-
sheet.insertRule(".need-server-info {\
272-
display: inline;\
273-
color: var(--link-server-disconnected);\
274-
opacity: 0.5;\
275-
}");
276270
}
277271
}
278272

0 commit comments

Comments
 (0)