From 3f37fb2936dab2fc34579b3db536e1fab1a95192 Mon Sep 17 00:00:00 2001 From: Rowan Date: Tue, 27 Apr 2021 20:18:15 +0100 Subject: [PATCH] Added Parameter to LaunchBrowser to set path --- tool/net/redbean.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tool/net/redbean.c b/tool/net/redbean.c index cffbdf1c5..ad4e89b65 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -2003,7 +2003,7 @@ static char *GetBasicAuthorization(size_t *z) { } } -static void LaunchBrowser() { +static void LaunchBrowser(const char *path) { char openbrowsercommand[255]; char *prog; if (IsWindows()) { @@ -2015,8 +2015,12 @@ static void LaunchBrowser() { } struct in_addr addr = serveraddr.sin_addr; if (addr.s_addr == INADDR_ANY) addr.s_addr = htonl(INADDR_LOOPBACK); - snprintf(openbrowsercommand, sizeof(openbrowsercommand), "%s http://%s:%d", - prog, inet_ntoa(addr), ntohs(serveraddr.sin_port)); + const char *pathname = path; + if (path == NULL) { + pathname = "/"; + } + snprintf(openbrowsercommand, sizeof(openbrowsercommand), "%s http://%s:%d%s", + prog, inet_ntoa(addr), ntohs(serveraddr.sin_port), pathname); DEBUGF("Opening browser with command %s\n", openbrowsercommand); system(openbrowsercommand); } @@ -3551,7 +3555,8 @@ static void LuaSetIntField(lua_State *L, const char *k, lua_Integer v) { } static int LuaLaunchBrowser(lua_State *L) { - LaunchBrowser(); + const char *p = luaL_checkstring(L, 1); + LaunchBrowser(p); return 1; }