Skip to content

Commit 0c12da8

Browse files
committed
improve mem management for http cmd
1 parent c6caa41 commit 0c12da8

File tree

1 file changed

+36
-42
lines changed

1 file changed

+36
-42
lines changed

src/Abstracts/ANetworkController.cpp

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -463,19 +463,17 @@ void ANetworkController::handleHttpGet(const TerminalCommand &cmd)
463463
std::string url = argTransformer.ensureHttpScheme(arg);
464464

465465
terminalView.println("HTTP: Sending GET request to " + url + "...");
466-
467-
httpService.startGetTask(url, 5000, 8192, true, 20000);
466+
httpService.startGetTask(url, 10000, 8192, true, 30000);
468467

469468
// Wait until timeout or response is ready
470-
const unsigned long deadline = millis() + 5000;
469+
const unsigned long deadline = millis() + 10000;
471470
while (!httpService.isResponseReady() && millis() < deadline) {
472471
delay(50);
473472
}
474473

475474
if (httpService.isResponseReady()) {
476475
terminalView.println("\n========== HTTP GET =============");
477-
auto formatted = argTransformer.normalizeLines(httpService.lastResponse());
478-
terminalView.println(formatted);
476+
terminalView.println(argTransformer.normalizeLines(httpService.lastResponse()));
479477
terminalView.println("=================================\n");
480478

481479
} else {
@@ -499,51 +497,47 @@ void ANetworkController::handleHttpAnalyze(const TerminalCommand& cmd)
499497
const std::string url = argTransformer.ensureHttpScheme(cmd.getArgs());
500498
const std::string host = argTransformer.extractHostFromUrl(url);
501499
std::vector<std::string> lines;
500+
std::string resp;
502501

503502
// === urlscan.io (last public scan) ====
504-
{ // scope to limit variable lifetime
505-
const std::string urlscanUrl =
506-
"https://urlscan.io/api/v1/search?datasource=scans&q=page.domain:" + host + "&size=1";
507-
508-
terminalView.println("HTTP Analyze: " + urlscanUrl + " (latest public scan)...");
509-
std::string urlscanJson = httpService.fetchJson(urlscanUrl, 8192);
510-
terminalView.println("\n===== URLSCAN LATEST =====");
511-
lines = jsonTransformer.toLines(jsonTransformer.dechunk(urlscanJson));
512-
for (auto& l : lines) terminalView.println(l);
513-
terminalView.println("==========================\n");
514-
}
503+
const std::string urlscanUrl =
504+
"https://urlscan.io/api/v1/search?datasource=scans&q=page.domain:" + host + "&size=1";
505+
506+
terminalView.println("HTTP Analyze: " + urlscanUrl + " (latest public scan)...");
507+
resp = httpService.fetchJson(urlscanUrl, 8192);
508+
terminalView.println("\n===== URLSCAN LATEST =====");
509+
lines = jsonTransformer.toLines(jsonTransformer.dechunk(resp));
510+
for (auto& l : lines) terminalView.println(l);
511+
terminalView.println("==========================\n");
512+
515513

516514
// === ssllabs.com ====
517-
{ // scope to limit variable lifetime
518-
const std::string ssllabsUrl =
519-
"https://api.ssllabs.com/api/v3/analyze?host=" + url;
520-
515+
const std::string ssllabsUrl =
516+
"https://api.ssllabs.com/api/v3/analyze?host=" + url;
517+
521518

522-
terminalView.println("HTTP Analyze: " + ssllabsUrl + " (SSL Labs)...");
523-
std::string ssllabsJson = httpService.fetchJson(ssllabsUrl, 16384);
519+
terminalView.println("HTTP Analyze: " + ssllabsUrl + " (SSL Labs)...");
520+
resp = httpService.fetchJson(ssllabsUrl, 16384);
524521

525-
terminalView.println("\n===== SSL LABS =====");
526-
lines = jsonTransformer.toLines(jsonTransformer.dechunk(ssllabsJson));
527-
for (auto& l : lines) terminalView.println(l);
528-
terminalView.println("====================\n");
529-
httpService.reset();
530-
}
522+
terminalView.println("\n===== SSL LABS =====");
523+
lines = jsonTransformer.toLines(jsonTransformer.dechunk(resp));
524+
for (auto& l : lines) terminalView.println(l);
525+
terminalView.println("====================\n");
526+
httpService.reset();
531527

532528
// ==== W3C HTML Validator (optional) ====
533-
{ // scope to limit variable lifetime
534-
auto confirm = userInputManager.readYesNo("\nAnalyze with the W3C Validator?", false);
535-
if (confirm) {
536-
const std::string w3cUrl =
537-
"https://validator.w3.org/nu/?out=json&doc=" + url;
538-
539-
terminalView.println("Analyze: " + w3cUrl + " (W3C validator)...");
540-
std::string w3cJson = httpService.fetchJson(w3cUrl, 16384);
541-
terminalView.println("\n===== W3C RESULT =====");
542-
lines = jsonTransformer.toLines(jsonTransformer.dechunk(w3cJson));
543-
for (auto& l : lines) terminalView.println(l);
544-
terminalView.println("======================\n");
545-
httpService.reset();
546-
}
529+
auto confirm = userInputManager.readYesNo("\nAnalyze with the W3C Validator?", false);
530+
if (confirm) {
531+
const std::string w3cUrl =
532+
"https://validator.w3.org/nu/?out=json&doc=" + url;
533+
534+
terminalView.println("Analyze: " + w3cUrl + " (W3C validator)...");
535+
resp = httpService.fetchJson(w3cUrl, 16384);
536+
terminalView.println("\n===== W3C RESULT =====");
537+
lines = jsonTransformer.toLines(jsonTransformer.dechunk(resp));
538+
for (auto& l : lines) terminalView.println(l);
539+
terminalView.println("======================\n");
540+
httpService.reset();
547541
}
548542
terminalView.println("\nHTTP Analyze: Finished.");
549543
}

0 commit comments

Comments
 (0)