mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-06 16:34:13 +00:00
validate connection step
This commit is contained in:
parent
c4086d866f
commit
9a0e9d3f17
@ -131,86 +131,100 @@ void Page::update()
|
|||||||
), .25
|
), .25
|
||||||
);
|
);
|
||||||
|
|
||||||
GioSocketConnection_RefPtr = GioSocketClient_RefPtr->connect_to_uri_finish(
|
try
|
||||||
result
|
{
|
||||||
);
|
GioSocketConnection_RefPtr = GioSocketClient_RefPtr->connect_to_uri_finish(
|
||||||
|
result
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Request
|
catch (const Glib::Error & EXCEPTION)
|
||||||
const Glib::ustring request = pageNavbar->get_request_text() + "\r\n";
|
{
|
||||||
|
set(
|
||||||
|
pageNavbar->get_request_host(),
|
||||||
|
EXCEPTION.what(), 1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
GioSocketConnection_RefPtr->get_output_stream()->write_async(
|
// Connection established, begin request
|
||||||
request.data(),
|
if (GioSocketConnection_RefPtr != nullptr)
|
||||||
request.size(),
|
{
|
||||||
[this](const Glib::RefPtr<Gio::AsyncResult> & result)
|
const Glib::ustring request = pageNavbar->get_request_text() + "\r\n";
|
||||||
{
|
|
||||||
set(
|
|
||||||
pageNavbar->get_request_host(),
|
|
||||||
Glib::ustring::sprintf(
|
|
||||||
_("request %s.."),
|
|
||||||
pageNavbar->get_request_path().empty() ? pageNavbar->get_request_host()
|
|
||||||
: pageNavbar->get_request_path()
|
|
||||||
), .5
|
|
||||||
);
|
|
||||||
|
|
||||||
// Response
|
GioSocketConnection_RefPtr->get_output_stream()->write_async(
|
||||||
GioSocketConnection_RefPtr->get_input_stream()->read_async( // | read_all_async
|
request.data(),
|
||||||
buffer,
|
request.size(),
|
||||||
sizeof(buffer) - 1,
|
[this](const Glib::RefPtr<Gio::AsyncResult> & result)
|
||||||
[this](const Glib::RefPtr<Gio::AsyncResult> & result)
|
{
|
||||||
{
|
set(
|
||||||
set(
|
pageNavbar->get_request_host(),
|
||||||
pageNavbar->get_request_host(),
|
Glib::ustring::sprintf(
|
||||||
Glib::ustring::sprintf(
|
_("request %s.."),
|
||||||
_("reading %s.."),
|
pageNavbar->get_request_path().empty() ? pageNavbar->get_request_host()
|
||||||
pageNavbar->get_request_path().empty() ? pageNavbar->get_request_host()
|
: pageNavbar->get_request_path()
|
||||||
: pageNavbar->get_request_path()
|
), .5
|
||||||
), .75
|
);
|
||||||
);
|
|
||||||
|
|
||||||
// Parse meta
|
// Response
|
||||||
auto meta = Glib::Regex::split_simple(
|
GioSocketConnection_RefPtr->get_input_stream()->read_async( // | read_all_async
|
||||||
R"regex(^(\d+)?\s([\w]+\/[\w]+)?)regex",
|
buffer,
|
||||||
buffer
|
sizeof(buffer) - 1,
|
||||||
);
|
[this](const Glib::RefPtr<Gio::AsyncResult> & result)
|
||||||
|
|
||||||
// Route by status code
|
|
||||||
if (meta[1] == "20")
|
|
||||||
{
|
{
|
||||||
// Route by mime type or path extension
|
set(
|
||||||
if (meta[2] == "text/gemini" || Glib::str_has_suffix(pageNavbar->get_request_path(), ".gmi"))
|
pageNavbar->get_request_host(),
|
||||||
|
Glib::ustring::sprintf(
|
||||||
|
_("reading %s.."),
|
||||||
|
pageNavbar->get_request_path().empty() ? pageNavbar->get_request_host()
|
||||||
|
: pageNavbar->get_request_path()
|
||||||
|
), .75
|
||||||
|
);
|
||||||
|
|
||||||
|
// Parse meta
|
||||||
|
auto meta = Glib::Regex::split_simple(
|
||||||
|
R"regex(^(\d+)?\s([\w]+\/[\w]+)?)regex",
|
||||||
|
buffer
|
||||||
|
);
|
||||||
|
|
||||||
|
// Route by status code
|
||||||
|
if (meta[1] == "20")
|
||||||
{
|
{
|
||||||
pageContent->set_text_gemini(
|
// Route by mime type or path extension
|
||||||
buffer // @TODO
|
if (meta[2] == "text/gemini" || Glib::str_has_suffix(pageNavbar->get_request_path(), ".gmi"))
|
||||||
);
|
{
|
||||||
|
pageContent->set_text_gemini(
|
||||||
|
buffer // @TODO
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pageContent->set_text_plain(
|
||||||
|
_("MIME type not supported")
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pageContent->set_text_plain(
|
pageContent->set_text_plain(
|
||||||
_("MIME type not supported")
|
_("Could not open page")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
else
|
GioSocketConnection_RefPtr->close();
|
||||||
{
|
|
||||||
pageContent->set_text_plain(
|
set(
|
||||||
_("Could not open page")
|
pageNavbar->get_request_host(), // @TODO title
|
||||||
|
pageNavbar->get_request_path().empty() ? pageNavbar->get_request_host()
|
||||||
|
: pageNavbar->get_request_path()
|
||||||
|
, 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
);
|
||||||
GioSocketConnection_RefPtr->close();
|
}
|
||||||
|
);
|
||||||
set(
|
}
|
||||||
pageNavbar->get_request_host(), // @TODO title
|
|
||||||
pageNavbar->get_request_path().empty() ? pageNavbar->get_request_host()
|
|
||||||
: pageNavbar->get_request_path()
|
|
||||||
, 1
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user