mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
implement redirect follow
This commit is contained in:
parent
aecaeaa7a2
commit
742b441fb6
2 changed files with 45 additions and 4 deletions
12
config.json
12
config.json
|
|
@ -17,6 +17,18 @@
|
||||||
{
|
{
|
||||||
"page":
|
"page":
|
||||||
{
|
{
|
||||||
|
"redirect":
|
||||||
|
{
|
||||||
|
"follow":
|
||||||
|
{
|
||||||
|
"enabled":true,
|
||||||
|
"code":
|
||||||
|
[
|
||||||
|
30,
|
||||||
|
31
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"resolver":
|
"resolver":
|
||||||
{
|
{
|
||||||
"enabled":true,
|
"enabled":true,
|
||||||
|
|
|
||||||
|
|
@ -313,7 +313,8 @@ class Page
|
||||||
|
|
||||||
public function open(
|
public function open(
|
||||||
string $url,
|
string $url,
|
||||||
bool $history = true
|
bool $history = true,
|
||||||
|
int $code = 0
|
||||||
): void
|
): void
|
||||||
{
|
{
|
||||||
// Update address field by requested
|
// Update address field by requested
|
||||||
|
|
@ -350,7 +351,8 @@ class Page
|
||||||
case str_starts_with($url, 'gemini://'):
|
case str_starts_with($url, 'gemini://'):
|
||||||
|
|
||||||
$this->_gemini(
|
$this->_gemini(
|
||||||
$url
|
$url,
|
||||||
|
$code
|
||||||
);
|
);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -363,7 +365,10 @@ class Page
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _gemini(string $url): void
|
private function _gemini(
|
||||||
|
string $url,
|
||||||
|
int $code = 0
|
||||||
|
): void
|
||||||
{
|
{
|
||||||
// Track response time
|
// Track response time
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
|
|
@ -417,6 +422,26 @@ class Page
|
||||||
$raw
|
$raw
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Process redirect
|
||||||
|
if ($this->config->redirect->follow->enabled && in_array($response->getCode(), $this->config->redirect->follow->code))
|
||||||
|
{
|
||||||
|
$redirect = new \Yggverse\Net\Address(
|
||||||
|
$url
|
||||||
|
);
|
||||||
|
|
||||||
|
$redirect->setPath(
|
||||||
|
$response->getMeta()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->open(
|
||||||
|
$redirect->get(),
|
||||||
|
false,
|
||||||
|
$response->getCode()
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->content->set_markup(
|
$this->content->set_markup(
|
||||||
\Yggverse\Gemini\Pango::fromGemtext(
|
\Yggverse\Gemini\Pango::fromGemtext(
|
||||||
$response->getBody()
|
$response->getBody()
|
||||||
|
|
@ -445,6 +470,7 @@ class Page
|
||||||
[
|
[
|
||||||
'{NAVIGATION_ADDRESS}',
|
'{NAVIGATION_ADDRESS}',
|
||||||
'{TIME_C}',
|
'{TIME_C}',
|
||||||
|
'{RESPONSE_CODE}',
|
||||||
'{RESPONSE_META}',
|
'{RESPONSE_META}',
|
||||||
'{RESPONSE_LENGTH}',
|
'{RESPONSE_LENGTH}',
|
||||||
'{RESPONSE_SECONDS}'
|
'{RESPONSE_SECONDS}'
|
||||||
|
|
@ -456,7 +482,10 @@ class Page
|
||||||
date(
|
date(
|
||||||
'c'
|
'c'
|
||||||
),
|
),
|
||||||
$response->getMeta() ? $response->getMeta() : $response->getCode(),
|
$response->getCode(),
|
||||||
|
($code ? sprintf('%d:', $code) : '')
|
||||||
|
.
|
||||||
|
($response->getMeta() ? $response->getMeta() : $response->getCode()),
|
||||||
number_format(
|
number_format(
|
||||||
mb_strlen(
|
mb_strlen(
|
||||||
$raw
|
$raw
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue