[PATCH] Add "prefix" option to "hg serve", useful when running behind a reverse proxy
Michele Cella
michele.cella at gmail.com
Mon Jan 7 20:33:13 UTC 2008
# HG changeset patch
# User Michele Cella <michele.cella at gmail.com>
# Date 1199731663 -3600
# Node ID 77a77c3f41bd531a96e161ddb10f3c7908e7ae87
# Parent 956e01c31914baa49cf87a5b97b38781797cfcf9
introducing the "prefix" configuration option in the "web" section
allows "hg serve" to serve from any prefix, not just root ('/')
diff -r 956e01c31914 -r 77a77c3f41bd mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py Thu Jan 03 20:27:32 2008 -0600
+++ b/mercurial/hgweb/server.py Mon Jan 07 19:47:43 2008 +0100
@@ -76,7 +76,7 @@ class _hgwebhandler(object, BaseHTTPServ
self.do_POST()
def do_hgweb(self):
- path_info, query = _splitURI(self.path)
+ path, query = _splitURI(self.path)
env = {}
env['GATEWAY_INTERFACE'] = 'CGI/1.1'
@@ -84,8 +84,8 @@ class _hgwebhandler(object, BaseHTTPServ
env['SERVER_NAME'] = self.server.server_name
env['SERVER_PORT'] = str(self.server.server_port)
env['REQUEST_URI'] = self.path
- env['SCRIPT_NAME'] = ''
- env['PATH_INFO'] = path_info
+ env['SCRIPT_NAME'] = self.server.prefix
+ env['PATH_INFO'] = path[len(self.server.prefix):]
env['REMOTE_HOST'] = self.client_address[0]
env['REMOTE_ADDR'] = self.client_address[0]
if query:
@@ -206,6 +206,7 @@ def create_server(ui, repo):
myui = repo.ui
address = myui.config("web", "address", "")
port = int(myui.config("web", "port", 8000))
+ prefix = myui.config("web", "prefix", "").rstrip("/")
use_ipv6 = myui.configbool("web", "ipv6")
webdir_conf = myui.config("web", "webdir_conf")
ssl_cert = myui.config("web", "certificate")
@@ -254,6 +255,7 @@ def create_server(ui, repo):
addr = socket.gethostname()
self.addr, self.port = addr, port
+ self.prefix = prefix
if ssl_cert:
try:
# HG changeset patch
# User Michele Cella <michele.cella at gmail.com>
# Date 1199734042 -3600
# Node ID 8a5cf08a0528c6553bdbf90164bebe4078e1e633
# Parent 77a77c3f41bd531a96e161ddb10f3c7908e7ae87
adding "prefix" command line option to "hg serve"
diff -r 77a77c3f41bd -r 8a5cf08a0528 mercurial/commands.py
--- a/mercurial/commands.py Mon Jan 07 19:47:43 2008 +0100
+++ b/mercurial/commands.py Mon Jan 07 20:27:22 2008 +0100
@@ -2393,7 +2393,7 @@ def serve(ui, repo, **opts):
s.serve_forever()
parentui = ui.parentui or ui
- optlist = ("name templates style address port ipv6"
+ optlist = ("name templates style address port prefix ipv6"
" accesslog errorlog webdir_conf certificate")
for o in optlist.split():
if opts[o]:
@@ -3024,6 +3024,7 @@ table = {
('E', 'errorlog', '', _('name of error log file to write to')),
('p', 'port', 0, _('port to use (default: 8000)')),
('a', 'address', '', _('address to use')),
+ ('', 'prefix', '', _('prefix path to serve from (default:
server root)')),
('n', 'name', '',
_('name to show in web pages (default: working dir)')),
('', 'webdir-conf', '', _('name of the webdir config file'
More information about the Mercurial-devel
mailing list