comparison mercurial/hgweb/hgweb_mod.py @ 5579:e15f7db0f0ee

Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Sat, 01 Dec 2007 19:19:08 +0100
parents d74fc8dec2b4
children 083b6e3142a2 08887121a652
comparison
equal deleted inserted replaced
5578:733b50883f73 5579:e15f7db0f0ee
724 del form[k] 724 del form[k]
725 725
726 def rewrite_request(req): 726 def rewrite_request(req):
727 '''translate new web interface to traditional format''' 727 '''translate new web interface to traditional format'''
728 728
729 def spliturl(req): 729 req.url = req.env['SCRIPT_NAME']
730 def firstitem(query): 730 if not req.url.endswith('/'):
731 return query.split('&', 1)[0].split(';', 1)[0] 731 req.url += '/'
732 732 if req.env.has_key('REPO_NAME'):
733 def normurl(url): 733 req.url += req.env['REPO_NAME'] + '/'
734 inner = '/'.join([x for x in url.split('/') if x]) 734
735 tl = len(url) > 1 and url.endswith('/') and '/' or '' 735 if req.env.get('PATH_INFO'):
736 736 parts = req.env.get('PATH_INFO').strip('/').split('/')
737 return '%s%s%s' % (url.startswith('/') and '/' or '', 737 repo_parts = req.env.get('REPO_NAME', '').split('/')
738 inner, tl) 738 if parts[:len(repo_parts)] == repo_parts:
739 739 parts = parts[len(repo_parts):]
740 root = normurl(urllib.unquote(req.env.get('REQUEST_URI', '').split('?', 1)[0])) 740 query = '/'.join(parts)
741 pi = normurl(req.env.get('PATH_INFO', '')) 741 else:
742 if pi: 742 query = req.env['QUERY_STRING'].split('&', 1)[0]
743 # strip leading / 743 query = query.split(';', 1)[0]
744 pi = pi[1:]
745 if pi:
746 root = root[:root.rfind(pi)]
747 if req.env.has_key('REPO_NAME'):
748 rn = req.env['REPO_NAME'] + '/'
749 root += rn
750 query = pi[len(rn):]
751 else:
752 query = pi
753 else:
754 root += '?'
755 query = firstitem(req.env['QUERY_STRING'])
756
757 return (root, query)
758
759 req.url, query = spliturl(req)
760 744
761 if req.form.has_key('cmd'): 745 if req.form.has_key('cmd'):
762 # old style 746 # old style
763 return 747 return
764 748