Snapshot file model, Hotspot restart on config change.

This commit is contained in:
Robin Davies
2024-10-08 02:40:05 -04:00
parent 94b2072783
commit ebe56f4df9
19 changed files with 651 additions and 193 deletions
+40
View File
@@ -936,6 +936,20 @@ namespace pipedal
return result.str();
}
static void splitAddressAndPort(const std::string &address, std::string&addrOnly, std::string&port)
{
size_t portPos = address.length();
for (size_t i = address.length(); i > 0; --i)
{
if (address[i-1] == ':')
{
portPos = i-1;
break;
}
}
addrOnly = address.substr(0,portPos);
port = address.substr(portPos);
}
void on_http(connection_hdl hdl)
{
// Upgrade our connection handle to a full connection_ptr
@@ -974,6 +988,31 @@ namespace pipedal
std::string fromAddress = SS(con->get_remote_endpoint());
// redirect requests to IPV6 local connections to a better address.
std::string addrOnly,portStr;
splitAddressAndPort(fromAddress,addrOnly,portStr);
if (IsLinkLocalAddress(addrOnly))
{
try {
uri_builder builder(requestUri);
std::string redirectAddress = GetNonLinkLocalAddress(addrOnly);
builder.set_authority(redirectAddress+portStr);
std::string redirectUri = builder.str();
res.set(HttpField::location,redirectUri.c_str());
Lv2Log::info(SS("Redirecting from " << fromAddress << " to " << redirectUri));
res.keepAlive(false);
con->set_status(websocketpp::http::status_code::temporary_redirect);
return;
} catch (const std::exception&e)
{
ServerError(*con,"Invalid request on link-local address.");
return;
}
}
if (req.method() == HttpVerb::options)
{
res.set(HttpField::access_control_allow_origin, origin);
@@ -984,6 +1023,7 @@ namespace pipedal
return;
}
for (auto requestHandler : this->request_handlers)
{