diff --git a/config.json b/config.json index 4fa79e9..706079e 100644 --- a/config.json +++ b/config.json @@ -22,6 +22,7 @@ "follow": { "enabled":true, + "max":5, "code": [ 30, diff --git a/src/Entity/Tab/Page.php b/src/Entity/Tab/Page.php index d366262..7fb041d 100644 --- a/src/Entity/Tab/Page.php +++ b/src/Entity/Tab/Page.php @@ -367,7 +367,8 @@ class Page private function _gemini( string $url, - int $code = 0 + int $code = 0, + int $redirects = 0 ): void { // Track response time @@ -423,23 +424,45 @@ class Page ); // Process redirect - if ($this->config->redirect->follow->enabled && in_array($response->getCode(), $this->config->redirect->follow->code)) + if (in_array($response->getCode(), $this->config->redirect->follow->code)) { - $redirect = new \Yggverse\Net\Address( - $url - ); + if ($this->config->redirect->follow->enabled) + { + if ($redirects > $this->config->redirect->follow->max) + { + $this->_yoda( + 'yoda://redirect' + ); - $redirect->setPath( - $response->getMeta() - ); + return; + } - $this->open( - $redirect->get(), - false, - $response->getCode() - ); + $redirect = new \Yggverse\Net\Address( + $url + ); + + $redirect->setPath( + $response->getMeta() + ); + + $this->open( + $redirect->get(), + false, + $response->getCode(), + $redirects + 1 + ); + + return; + } + + else + { + $this->_yoda( + 'yoda://redirect' + ); - return; + return; + } } $this->content->set_markup( diff --git a/src/Page/Redirect.gmi b/src/Page/Redirect.gmi new file mode 100644 index 0000000..3cabf1d --- /dev/null +++ b/src/Page/Redirect.gmi @@ -0,0 +1,8 @@ +# Redirect issue + +You see this message because page redirect could not be processed properly + +## Possible reasons + +* Max redirects reached +* Redirects disabled by settings \ No newline at end of file