diff --git a/http.c b/http.c index 5d1cf4e14207cac25c3d424c624de0e35a84e011..de6d73b20c7a535183fc1caf0c4e5b8e0e77f893 100644 --- a/http.c +++ b/http.c @@ -851,15 +851,19 @@ } static int l_http_static(lua_State *L) { const char *path = luaL_checkstring(L, 1); + char resolved[PATH_MAX]; + if (!realpath(path, resolved)) { + return luaL_error(L, "Could not resolve static directory: %s", path); + } if (static_dir) { free(static_dir); } - char resolved[PATH_MAX]; - if (realpath(path, resolved)) { - static_dir = strdup(resolved); - } else { - static_dir = strdup(path); + // Remove trailing slash if present + size_t len = strlen(resolved); + if (len > 1 && resolved[len - 1] == '/') { + resolved[len - 1] = '\0'; } + static_dir = strdup(resolved); return 0; }