From 71e3c270c416f8abb7c3370bbb087bc098ef2625 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 21 Apr 2024 14:38:54 +0300 Subject: [PATCH] draft nex protocol support --- README.md | 5 ++ composer.json | 1 + src/Entity/Tab/Page.php | 136 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+) diff --git a/README.md b/README.md index a8694ec..85b9da7 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,11 @@ At this moment project under development! +## Protocols + +* [x] Gemini +* [ ] Nex + ## Features * [x] Custom DNS resolver with memory cache (useful for alt networks like [Yggdrasil](https://github.com/yggdrasil-network/yggdrasil-go)) diff --git a/composer.json b/composer.json index c9c95d4..bc71947 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,7 @@ "type": "project", "require": { "yggverse/gemini": "dev-main", + "yggverse/nex": "dev-main", "yggverse/net": "dev-main" }, "license": "MIT", diff --git a/src/Entity/Tab/Page.php b/src/Entity/Tab/Page.php index b8cec05..42d4185 100644 --- a/src/Entity/Tab/Page.php +++ b/src/Entity/Tab/Page.php @@ -560,6 +560,14 @@ class Page break; + case str_starts_with($url, 'nex://'): + + $this->_openNex( + $url + ); + + break; + case str_starts_with($url, 'yoda://'): $this->_openYoda( @@ -797,6 +805,134 @@ class Page } } + private function _openNex( + string $url, + bool $history = true + ): void + { + // Init progressbar + if ($this->config->progressbar->visible) + { + $this->setProgress(0); + } + + // Init base URL + $origin = new \Yggverse\Net\Address( + $url + ); + + // Track response time + $start = microtime(true); + + // Init custom resolver + $host = null; + + if ($this->config->resolver->enabled) + { + $address = new \Yggverse\Net\Address( + $url + ); + + $name = $address->getHost(); + + if (!$host = $this->dns->get($name)) + { + $resolve = new \Yggverse\Net\Resolve( + $this->config->resolver->request->record, + $this->config->resolver->request->host, + $this->config->resolver->request->timeout, + $this->config->resolver->result->shuffle + ); + + $resolved = $resolve->address( + $address + ); + + if ($resolved) + { + $host = $resolved->getHost(); + + $this->dns->set( + $name, + $host + ); + } + } + } + + $request = new \Yggverse\Nex\Client\Request( + $url, + $host + ); + + $raw = $request->getResponse(); + + $end = microtime(true); + + $this->content->set_markup( + $raw // @TODO + ); + + $this->setTitle( + $origin->getHost() + ); + + $this->status->set_markup( + str_replace( // Custom macros mask from config.json + [ + '{TIME_C}', + '{REQUEST_BASE}', + '{REQUEST_BASE_URL}', + '{RESPONSE_CODE}', + '{RESPONSE_META}', + '{RESPONSE_LENGTH}', + '{RESPONSE_SECONDS}' + ], + [ + date( + 'c' + ), + $origin->getHost(), + sprintf( + '%s', + $origin->get( + true, // scheme + true, // user + true, // pass + true, // host + true, // port + false, // path + false, // query + false // fragment + ), + $origin->getHost() + ), + '-', // @TODO + '-', + number_format( + mb_strlen( + $raw + ) + ), + round( + $end - $start, 2 + ) + ], + $this->config->footer->status->open->complete + ) + ); + + // Update history database + if ($history && $this->config->history->database->enabled) + { + $this->app->history->add( + $url, + $title, + $this->config->history->database->mode->renew + ); + } + } + private function _openYoda( string $url ): void