summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2008-12-26 09:33:01 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2008-12-26 09:33:01 (UTC)
commit377a1c8cedcbd18f42e45c6ab757a603af44df33 (patch) (unidiff)
tree8cfe705b3e68cafc913e7aee62033552082adf47
parent11456a60deab19f5e3a1d191bdf48adfba9195e4 (diff)
downloadcgit-377a1c8cedcbd18f42e45c6ab757a603af44df33.zip
cgit-377a1c8cedcbd18f42e45c6ab757a603af44df33.tar.gz
cgit-377a1c8cedcbd18f42e45c6ab757a603af44df33.tar.bz2
Untie logic for SCRIPT_NAME and PATH_INFO
SCRIPT_NAME is used as fallback for virtual-root when virtual-root is unspecified in cgitrc and PATH_INFO is used as fallback for the query- string parameter 'url' when the latter is unspecified. But until now, the use of PATH_INFO depended on virtual-root also being unspecified, i.e. it was impossible to use PATH_INFO when virtual-root was specified. This commit makes the fallback on SCRIPT_NAME and PATH_INFO independent code paths, i.e. it is now possible to specify virtual-root in cgitrc while still using PATH_INFO (instead of rewrite rules) to get 'pretty urls'. Noticed-by: Jack Moffitt <jack@chesspark.com> Noticed-by: LiKai Liu <liulk@cs.bu.edu> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--cgit.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/cgit.c b/cgit.c
index 166fbc6..d1cee58 100644
--- a/cgit.c
+++ b/cgit.c
@@ -436,35 +436,36 @@ int main(int argc, const char **argv)
436 cgit_parse_args(argc, argv); 436 cgit_parse_args(argc, argv);
437 parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG, 437 parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG,
438 config_cb); 438 config_cb);
439 ctx.repo = NULL; 439 ctx.repo = NULL;
440 http_parse_querystring(ctx.qry.raw, querystring_cb); 440 http_parse_querystring(ctx.qry.raw, querystring_cb);
441 441
442 /* If virtual-root isn't specified in cgitrc and no url 442 /* If virtual-root isn't specified in cgitrc, lets pretend
443 * parameter is specified on the querystring, lets pretend 443 * that virtual-root equals SCRIPT_NAME.
444 * that virtualroot equals SCRIPT_NAME and use PATH_INFO as
445 * url. This allows cgit to work with virtual urls without
446 * the need for rewriterules in the webserver (as long as
447 * PATH_INFO is included in the cache lookup key).
448 */ 444 */
449 if (!ctx.cfg.virtual_root && !ctx.qry.url) { 445 if (!ctx.cfg.virtual_root)
450 ctx.cfg.virtual_root = ctx.cfg.script_name; 446 ctx.cfg.virtual_root = ctx.cfg.script_name;
447
448 /* If no url parameter is specified on the querystring, lets
449 * use PATH_INFO as url. This allows cgit to work with virtual
450 * urls without the need for rewriterules in the webserver (as
451 * long as PATH_INFO is included in the cache lookup key).
452 */
451 path = getenv("PATH_INFO"); 453 path = getenv("PATH_INFO");
452 if (path) { 454 if (!ctx.qry.url && path) {
453 if (path[0] == '/') 455 if (path[0] == '/')
454 path++; 456 path++;
455 ctx.qry.url = xstrdup(path); 457 ctx.qry.url = xstrdup(path);
456 if (ctx.qry.raw) { 458 if (ctx.qry.raw) {
457 qry = ctx.qry.raw; 459 qry = ctx.qry.raw;
458 ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry)); 460 ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry));
459 free(qry); 461 free(qry);
460 } else 462 } else
461 ctx.qry.raw = ctx.qry.url; 463 ctx.qry.raw = ctx.qry.url;
462 cgit_parse_url(ctx.qry.url); 464 cgit_parse_url(ctx.qry.url);
463 } 465 }
464 }
465 466
466 ttl = calc_ttl(); 467 ttl = calc_ttl();
467 ctx.page.expires += ttl*60; 468 ctx.page.expires += ttl*60;
468 if (ctx.cfg.nocache) 469 if (ctx.cfg.nocache)
469 ctx.cfg.cache_size = 0; 470 ctx.cfg.cache_size = 0;
470 err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, 471 err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,