Mercurial > hg
comparison mercurial/hgweb/hgweb_mod.py @ 3327:e6353b7b102a
NWI base URL detection fixes
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Tue, 10 Oct 2006 10:28:20 -0700 |
parents | 0708bdb4987a |
children | 8ec80c1b8f0b |
comparison
equal
deleted
inserted
replaced
3324:34f08b8883cf | 3327:e6353b7b102a |
---|---|
645 | 645 |
646 def spliturl(req): | 646 def spliturl(req): |
647 def firstitem(query): | 647 def firstitem(query): |
648 return query.split('&', 1)[0].split(';', 1)[0] | 648 return query.split('&', 1)[0].split(';', 1)[0] |
649 | 649 |
650 root = req.env.get('REQUEST_URI', '').split('?', 1)[0] | 650 def normurl(url): |
651 pi = req.env.get('PATH_INFO', '') | 651 inner = '/'.join([x for x in url.split('/') if x]) |
652 tl = len(url) > 1 and url.endswith('/') and '/' or '' | |
653 | |
654 return '%s%s%s' % (url.startswith('/') and '/' or '', | |
655 inner, tl) | |
656 | |
657 root = normurl(req.env.get('REQUEST_URI', '').split('?', 1)[0]) | |
658 pi = normurl(req.env.get('PATH_INFO', '')) | |
652 if pi: | 659 if pi: |
653 root = root[:-len(pi)] | 660 # strip leading / |
654 | 661 pi = pi[1:] |
655 if req.env.has_key('REPO_NAME'): | 662 if pi: |
656 base = '/' + req.env['REPO_NAME'] | 663 root = root[:-len(pi)] |
664 if req.env.has_key('REPO_NAME'): | |
665 rn = req.env['REPO_NAME'] + '/' | |
666 root += rn | |
667 query = pi[len(rn):] | |
668 else: | |
669 query = pi | |
657 else: | 670 else: |
658 base = root | 671 root += '?' |
659 | |
660 if pi: | |
661 while pi.startswith('//'): | |
662 pi = pi[1:] | |
663 if pi.startswith(base): | |
664 if len(pi) > len(base): | |
665 base += '/' | |
666 query = pi[len(base):] | |
667 else: | |
668 if req.env.has_key('REPO_NAME'): | |
669 # We are using hgwebdir | |
670 base += '/' | |
671 else: | |
672 base += '?' | |
673 query = firstitem(req.env['QUERY_STRING']) | |
674 else: | |
675 base += '/' | |
676 query = pi[1:] | |
677 else: | |
678 base += '?' | |
679 query = firstitem(req.env['QUERY_STRING']) | 672 query = firstitem(req.env['QUERY_STRING']) |
680 | 673 |
681 return (root + base, query) | 674 return (root, query) |
682 | 675 |
683 req.url, query = spliturl(req) | 676 req.url, query = spliturl(req) |
684 | 677 |
685 if req.form.has_key('cmd'): | 678 if req.form.has_key('cmd'): |
686 # old style | 679 # old style |