Implement url and scriptname autodetection.
Mon Jul 31 04:10:20 UTC 2006 Alberto Bertogli <albertito@gmail.com>
* Implement url and scriptname autodetection.
This patch implements autodetection of the url and scriptname of darcsweb.
It's based on a suggestion from Tobias Gruetzmacher.
It relies on variables according to the CGI/1.1 standard, and works only if
cache is not enabled. If it is, the variables must be set manually as before.
The problem with the cache is multi-host access: if a page not in the cache is
accesed as http://hosta/dw/..., then the cached page will reference "hosta".
If then it's accessed from hostb, there will be a reference to hosta that it's
possibly broken. It's actually a quite common case when you have localhost and
external access.
{
hunk ./config.py.sample 4
- # this script's name, usually just "darcsweb.cgi" unless you rename it
- myname = "darcsweb.cgi"
-
- # our url, used only to generate RSS links, without the script name
- myurl = "http://example.com/darcsweb"
-
hunk ./config.py.sample 13
+ # this script's name, usually just "darcsweb.cgi" unless you rename
+ # it; if you leave this commented it will be detected automatically
+ #myname = "darcsweb.cgi"
+
+ # our url, used only to generate RSS links, without the script name;
+ # if you leave this commented it will be detected automatically
+ #myurl = "http://example.com/darcsweb"
+
hunk ./config.py.sample 43
+ # If you use this option you must set the "myname" and "myurl"
+ # variables.
hunk ./darcsweb.cgi 2060
+ expand_multi_config(all_configs)
hunk ./darcsweb.cgi 2104
- expand_multi_config(all_configs)
hunk ./darcsweb.cgi 2126
- 'myname': all_configs.base.myname,
+ 'myname': config.myname,
hunk ./darcsweb.cgi 2232
- config.myname = base.myname
- config.myurl = base.myurl
+ if 'myname' not in dir(base):
+ # SCRIPT_NAME has the full path, we only take the file name
+ config.myname = os.path.basename(os.environ['SCRIPT_NAME'])
+ else:
+ config.myname = base.myname
+
+ if 'myurl' not in dir(base) and 'cachedir' not in dir(base):
+ n = os.environ['SERVER_NAME']
+ p = os.environ['SERVER_PORT']
+ s = os.environ['SCRIPT_NAME']
+ if p == '80':
+ p = ''
+ else:
+ p = ':' + p
+ config.myurl = 'http://%s%s%s' % (n, p, s)
+ else:
+ config.myurl = base.myurl
+
hunk ./darcsweb.cgi 2254
- config.myreponame = base.myname + '?r=' + urllib.quote(name)
+ config.myreponame = config.myname + '?r=' + urllib.quote(name)
}