Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Set the virtual root from SCRIPT_NAME up front
The script name always holds a value, so the fallback after parsing
fired whenever cgitrc left virtual-root unset. The root is now set with
the other defaults, for cgitrc to replace. A die while cgitrc is read
is the one change, and its page now links the root with the trailing
slash every other page has. The environment's copy of the script name
only fed this.
Diffstat (limited to 'source/cgit.c')
| -rw-r--r-- | source/cgit.c | 11 |
1 file changed, 5 insertions, 6 deletions
diff --git a/source/cgit.c b/source/cgit.c index eaf1d19..715db59 100644 --- a/source/cgit.c +++ b/source/cgit.c @@ -91,6 +91,8 @@ static NORETURN void die_routine(const char *msg, va_list params) static void prepare_context(void) { + const char *script_name = getenv("SCRIPT_NAME"); + memset(&ctx, 0, sizeof(ctx)); ctx.cfg.agefile = "info/web/last-modified"; ctx.cfg.cache_size = 0; @@ -155,7 +157,6 @@ static void prepare_context(void) ctx.env.path_info = getenv("PATH_INFO"); ctx.env.query_string = getenv("QUERY_STRING"); ctx.env.request_method = getenv("REQUEST_METHOD"); - ctx.env.script_name = getenv("SCRIPT_NAME"); ctx.env.server_name = getenv("SERVER_NAME"); ctx.env.server_port = getenv("SERVER_PORT"); ctx.env.http_cookie = getenv("HTTP_COOKIE"); @@ -168,8 +169,9 @@ static void prepare_context(void) ctx.page.filename = NULL; ctx.page.size = 0; string_list_init_dup(&ctx.cfg.mimetypes); - if (ctx.env.script_name) - ctx.cfg.script_name = xstrdup(ctx.env.script_name); + if (script_name) + ctx.cfg.script_name = xstrdup(script_name); + ctx.cfg.virtual_root = cgit_ensure_end(ctx.cfg.script_name, '/'); if (ctx.env.query_string) ctx.qry.raw = xstrdup(ctx.env.query_string); if (!ctx.env.cgit_config) @@ -1349,9 +1351,6 @@ int cmd_main(int argc, const char **argv) ctx.repo = NULL; http_parse_querystring(ctx.qry.raw, apply_query_param); - if (!ctx.cfg.virtual_root && ctx.cfg.script_name) - ctx.cfg.virtual_root = cgit_ensure_end(ctx.cfg.script_name, '/'); - // Falling back to PATH_INFO lets cgit serve virtual urls without a // rewrite rule in the web server, and folding it into the raw query // string keeps it part of the cache key. |
