Stop using cv2pdb and improve HTTP handling a little

This commit is contained in:
2023-07-03 15:18:21 -04:00
parent ea10bddb0b
commit af62ac040f
4 changed files with 36 additions and 16 deletions

View File

@@ -457,13 +457,6 @@ HttpServerResponse World::http_serve(const HttpParser &request) {
return response;
}
// Get the name of the desired function.
std::string_view fn = request.first_path_component("index");
if (!sv::is_lua_id(fn)) {
response.fail(404, util::ss("not a function name: ", fn));
return response;
}
lua_State *L = state();
LuaVar www, func, reqtab;
LuaExtStack LS(L, www, func, reqtab);
@@ -476,11 +469,19 @@ HttpServerResponse World::http_serve(const HttpParser &request) {
return response;
}
// Get the name of the desired function.
std::string_view orig_fn = request.first_path_component("index");
eng::string lua_fn = HttpParser::to_lua_identifier(orig_fn);
if (lua_fn.empty()) {
response.fail(404, util::ss("cannot convert to lua function name: ", orig_fn));
return response;
}
// Get the closure. If there's no such closure,
// return a 404 Not Found to the client.
LS.rawget(func, www, fn);
LS.rawget(func, www, lua_fn);
if (!LS.isfunction(func)) {
response.fail(404, util::ss("no such function: www.", fn));
response.fail(404, util::ss("no such lua function: www.", lua_fn));
return response;
}
@@ -507,7 +508,7 @@ HttpServerResponse World::http_serve(const HttpParser &request) {
// a 500 Internal Server Error to the client.
int newtop = lua_gettop(L);
if ((newtop != oldtop + 1) || (!lua_istable(L, newtop))) {
response.fail(500, util::ss("lua function www.", fn, " didn't return a table"));
response.fail(500, util::ss("lua function www.", lua_fn, " didn't return a table"));
return response;
}