mirror of
https://github.com/EyeTrackVR/OpenIris.git
synced 2025-11-04 15:39:42 +08:00
update
- Fixed bug in request handler - needed to add support for non-param URL requests
This commit is contained in:
parent
2d1906c5cc
commit
c220bf6606
@ -65,10 +65,8 @@ void ProjectConfig::load()
|
|||||||
ESP.restart();
|
ESP.restart();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
log_d("Project config found - Config length: %d", configLen);
|
log_d("Project config found - Config length: %d", configLen);
|
||||||
}
|
|
||||||
|
|
||||||
char buff[configLen];
|
char buff[configLen];
|
||||||
getBytes("config", buff, configLen);
|
getBytes("config", buff, configLen);
|
||||||
|
|||||||
@ -42,7 +42,6 @@ void APIServer::setupServer()
|
|||||||
|
|
||||||
// Camera Routes
|
// Camera Routes
|
||||||
|
|
||||||
|
|
||||||
//! reserve enough memory for all routes - must be called after adding routes and before adding routes to route_map
|
//! reserve enough memory for all routes - must be called after adding routes and before adding routes to route_map
|
||||||
indexes.reserve(routes.size()); // this is done to avoid reallocation of memory and copying of data
|
indexes.reserve(routes.size()); // this is done to avoid reallocation of memory and copying of data
|
||||||
addRouteMap("builtin", routes, indexes); // add new route map to the route_map
|
addRouteMap("builtin", routes, indexes); // add new route map to the route_map
|
||||||
@ -80,19 +79,23 @@ void APIServer::handleRequest(AsyncWebServerRequest *request)
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
size_t params = request->params();
|
||||||
// Get the route
|
// Get the route
|
||||||
log_i("Request URL: %s", request->url().c_str());
|
log_i("Request URL: %s", request->url().c_str());
|
||||||
int params = request->params();
|
log_i("Request: %s", request->pathArg(0).c_str());
|
||||||
auto it_map = route_map.find(request->pathArg(0).c_str());
|
log_i("Request: %s", request->pathArg(1).c_str());
|
||||||
log_i("Request First Arg: %s", request->pathArg(0).c_str());
|
|
||||||
auto it_method = it_map->second.find(request->pathArg(1).c_str());
|
|
||||||
log_i("Request Second Arg: %s", request->pathArg(1).c_str());
|
|
||||||
|
|
||||||
for (int i = 0; i < params; i++)
|
auto it_map = route_map.find(request->pathArg(0).c_str());
|
||||||
|
auto it_method = it_map->second.find(request->pathArg(1).c_str());
|
||||||
|
|
||||||
|
log_d("Params: %d", params);
|
||||||
|
if (params > 0)
|
||||||
{
|
{
|
||||||
|
log_d("We have params!");
|
||||||
|
for (size_t i = 0; i < params; i++)
|
||||||
|
{
|
||||||
|
log_d("We are executing the for loop");
|
||||||
AsyncWebParameter *param = request->getParam(i);
|
AsyncWebParameter *param = request->getParam(i);
|
||||||
{
|
|
||||||
{
|
|
||||||
if (it_map != route_map.end())
|
if (it_map != route_map.end())
|
||||||
{
|
{
|
||||||
if (it_method != it_map->second.end())
|
if (it_method != it_map->second.end())
|
||||||
@ -102,24 +105,42 @@ void APIServer::handleRequest(AsyncWebServerRequest *request)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Command\"}");
|
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Command\"}");
|
||||||
request->redirect("/");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Map Index\"}");
|
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Map Index\"}");
|
||||||
request->redirect("/");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
log_i("%s[%s]: %s\n", _networkMethodsMap[request->method()].c_str(), param->name().c_str(), param->value().c_str());
|
log_i("%s[%s]: %s\n", _networkMethodsMap[request->method()].c_str(), param->name().c_str(), param->value().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
request->send(200, MIMETYPE_JSON, "{\"msg\":\"Command executed\"}");
|
else
|
||||||
}
|
|
||||||
catch (...) // catch all exceptions
|
|
||||||
{
|
{
|
||||||
request->send(400, MIMETYPE_JSON, "{\"msg\":\"An Error has occurred\"}");
|
log_d("No params, so we skipped the for loop");
|
||||||
|
if (it_map != route_map.end())
|
||||||
|
{
|
||||||
|
if (it_method != it_map->second.end())
|
||||||
|
{
|
||||||
|
log_d("We are trying to execute the function");
|
||||||
|
(*this.*(it_method->second))(request);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Command\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
request->send(400, MIMETYPE_JSON, "{\"msg\":\"Invalid Map Index\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
log_e("Error handling request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user