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>
This commit is contained in:
والد
11456a60de
کامیت
377a1c8ced
41
cgit.c
41
cgit.c
@ -439,28 +439,29 @@ int main(int argc, const char **argv)
|
||||
ctx.repo = NULL;
|
||||
http_parse_querystring(ctx.qry.raw, querystring_cb);
|
||||
|
||||
/* If virtual-root isn't specified in cgitrc and no url
|
||||
* parameter is specified on the querystring, lets pretend
|
||||
* that virtualroot equals SCRIPT_NAME and use PATH_INFO as
|
||||
* url. This allows cgit to work with virtual urls without
|
||||
* the need for rewriterules in the webserver (as long as
|
||||
* PATH_INFO is included in the cache lookup key).
|
||||
/* If virtual-root isn't specified in cgitrc, lets pretend
|
||||
* that virtual-root equals SCRIPT_NAME.
|
||||
*/
|
||||
if (!ctx.cfg.virtual_root && !ctx.qry.url) {
|
||||
if (!ctx.cfg.virtual_root)
|
||||
ctx.cfg.virtual_root = ctx.cfg.script_name;
|
||||
path = getenv("PATH_INFO");
|
||||
if (path) {
|
||||
if (path[0] == '/')
|
||||
path++;
|
||||
ctx.qry.url = xstrdup(path);
|
||||
if (ctx.qry.raw) {
|
||||
qry = ctx.qry.raw;
|
||||
ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry));
|
||||
free(qry);
|
||||
} else
|
||||
ctx.qry.raw = ctx.qry.url;
|
||||
cgit_parse_url(ctx.qry.url);
|
||||
}
|
||||
|
||||
/* If no url parameter is specified on the querystring, lets
|
||||
* use PATH_INFO as url. This allows cgit to work with virtual
|
||||
* urls without the need for rewriterules in the webserver (as
|
||||
* long as PATH_INFO is included in the cache lookup key).
|
||||
*/
|
||||
path = getenv("PATH_INFO");
|
||||
if (!ctx.qry.url && path) {
|
||||
if (path[0] == '/')
|
||||
path++;
|
||||
ctx.qry.url = xstrdup(path);
|
||||
if (ctx.qry.raw) {
|
||||
qry = ctx.qry.raw;
|
||||
ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry));
|
||||
free(qry);
|
||||
} else
|
||||
ctx.qry.raw = ctx.qry.url;
|
||||
cgit_parse_url(ctx.qry.url);
|
||||
}
|
||||
|
||||
ttl = calc_ttl();
|
||||
|
بارگذاری…
مرجع در شماره جدید
Block a user