Browse Source

add max redirects config

PHP-GTK3
yggverse 6 months ago
parent
commit
26b4095eb8
  1. 1
      config.json
  2. 29
      src/Entity/Tab/Page.php
  3. 8
      src/Page/Redirect.gmi

1
config.json

@ -22,6 +22,7 @@ @@ -22,6 +22,7 @@
"follow":
{
"enabled":true,
"max":5,
"code":
[
30,

29
src/Entity/Tab/Page.php

@ -367,7 +367,8 @@ class Page @@ -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,8 +424,19 @@ class Page @@ -423,8 +424,19 @@ 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))
{
if ($this->config->redirect->follow->enabled)
{
if ($redirects > $this->config->redirect->follow->max)
{
$this->_yoda(
'yoda://redirect'
);
return;
}
$redirect = new \Yggverse\Net\Address(
$url
);
@ -436,12 +448,23 @@ class Page @@ -436,12 +448,23 @@ class Page
$this->open(
$redirect->get(),
false,
$response->getCode()
$response->getCode(),
$redirects + 1
);
return;
}
else
{
$this->_yoda(
'yoda://redirect'
);
return;
}
}
$this->content->set_markup(
\Yggverse\Gemini\Pango::fromGemtext(
$response->getBody()

8
src/Page/Redirect.gmi

@ -0,0 +1,8 @@ @@ -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
Loading…
Cancel
Save