commit f7460d25aca1fc80918e79f833667105631b9447
parent 2dce468fc819fcfe39561f195dba111434edf828
Author: Andrew Laack <andrew@laack.co>
Date: Wed, 30 Sep 2026 11:13:39 -0500
Fixed issue with certain status codes causing infinite loops
Diffstat:
3 files changed, 25 insertions(+), 14 deletions(-)
diff --git a/README b/README
@@ -67,16 +67,17 @@ requests to hosts you'd use an identity for.
One of the main reasons this browser feels so much faster than other gemini
protocol browsers is because of its optional prefetch caching. This is
enabled by default. When you visit a site without an identity, a thread will
- be created that fetches the first 10 links on the page. This enables ~
- instantaneous visitation of those links. Prefetch caching is only enabled
- when you aren't using an identity for a domain. Per the gemtext
- specification, "clients must not automatically make any network connections
- as part of displaying links", so this mode of operation may be construed as
- non-compliant with the gemtext specification. I don't believe a file format
- specification should be prescriptive about such things. Additionally, if
- this was a feature in a http-based web browser, I would disable it. I
- perceive Gemini as being more trustworthy right now and thus am not
- concerned about having this defaulted on.
+ be created that fetches the first 10 links on the page, caching them if
+ they return a 2X status code. This enables ~ instantaneous visitation of
+ those links. Prefetch caching is only enabled when you aren't using an
+ identity for a domain. Per the gemtext specification, "clients must not
+ automatically make any network connections as part of displaying links",
+ so this mode of operation may be construed as non-compliant with the
+ gemtext specification. I don't believe a file format specification should be
+ prescriptive about such things. Additionally, if this was a feature in a
+ http-based web browser, I would disable it. I perceive Gemini as being
+ more trustworthy right now and thus am not concerned about having this
+ defaulted on.
History caching:
diff --git a/src/browser.cpp b/src/browser.cpp
@@ -153,6 +153,13 @@ bool Browser::goToSite(std::string url, bool addToHistory, bool refresh) {
return false;
}
+ int sc = site->getStatusCode();
+ if (sc < 10 || sc >= 40) {
+ delete site;
+ delete destination;
+ return false;
+ }
+
if(addToHistory) {
while((int)siteHistory.size() > previousIdx + 1) {
delete siteHistory[siteHistory.size() - 1];
@@ -168,7 +175,8 @@ bool Browser::goToSite(std::string url, bool addToHistory, bool refresh) {
currentSite = site;
if(urlString.find("gemini://") != std::string::npos) {
- if(id.keyPath == "" && id.crtPath == "") {
+ int sc = site->getStatusCode();
+ if(sc >= 20 && sc <= 29 && id.keyPath == "" && id.crtPath == "") {
visitedCache->addSite(urlString, *site);
}
}
@@ -210,7 +218,10 @@ void Browser::justCacheSite(Link link) {
}
if(site != nullptr) {
- preFetchCache->addSite(urlString, *site);
+ int sc = site->getStatusCode();
+ if(sc >= 20 && sc <= 29) {
+ preFetchCache->addSite(urlString, *site);
+ }
delete site;
}
diff --git a/src/render.cpp b/src/render.cpp
@@ -376,7 +376,7 @@ bool mainLoop(DrawState& ds, Browser& b, int input) {
// Broadly, we are moving away from a loop based approach, sequestering them to either browser with forward / backward
// or main.cpp / tests.
- while( (b.getCurrentSite()->getStatusCode() < 20 || b.getCurrentSite()->getStatusCode() > 29) && !ds.handleRedirect && !ds.handleInput) {
+ if( (b.getCurrentSite()->getStatusCode() < 20 || b.getCurrentSite()->getStatusCode() > 29) && !ds.handleRedirect && !ds.handleInput) {
if(b.getCurrentSite()->getStatusCode() >= 10 && b.getCurrentSite()->getStatusCode() <= 19) {
auto* st = b.getCurrentSite();
if(st != nullptr) {
@@ -396,7 +396,6 @@ bool mainLoop(DrawState& ds, Browser& b, int input) {
ds.redirInput = "";
ds.handleRedirect = true;
mainLoop(ds, b, KEY_RESIZE);
-
}
}