Show More
@@ -648,16 +648,43 b' class hgweb(object):' | |||
|
648 | 648 | def rewrite_request(req): |
|
649 | 649 | '''translate new web interface to traditional format''' |
|
650 | 650 | |
|
651 | def spliturl(req): | |
|
652 | def firstitem(query): | |
|
653 | return query.split('&', 1)[0].split(';', 1)[0] | |
|
654 | ||
|
655 | base = '' | |
|
656 | if req.env.has_key('REPO_NAME'): | |
|
657 | base = '/' + req.env['REPO_NAME'] | |
|
658 | elif req.env.get('SCRIPT_NAME'): | |
|
659 | base = req.env['SCRIPT_NAME'] | |
|
660 | ||
|
661 | pi = req.env.get('PATH_INFO') | |
|
662 | if pi: | |
|
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']) | |
|
680 | ||
|
681 | return (base, query) | |
|
682 | ||
|
683 | req.url, query = spliturl(req) | |
|
684 | ||
|
651 | 685 | if req.form.has_key('cmd'): |
|
652 | 686 | # old style |
|
653 | 687 | return |
|
654 | if req.env.has_key('SCRIPT_URL'): | |
|
655 | # run through web server | |
|
656 | base = req.env['SCRIPT_URL'] | |
|
657 | # strip repo and leading '/' or '?' | |
|
658 | query = req.env['REQUEST_URI'][len(base)+1:] | |
|
659 | else: | |
|
660 | query = req.env['PATH_INFO'][1:] | |
|
661 | 688 | |
|
662 | 689 | args = query.split('/', 2) |
|
663 | 690 | if not args or not args[0]: |
@@ -668,7 +695,9 b' class hgweb(object):' | |||
|
668 | 695 | if style != -1: |
|
669 | 696 | req.form['style'] = [cmd[:style]] |
|
670 | 697 | cmd = cmd[style+1:] |
|
671 | req.form['cmd'] = [cmd] | |
|
698 | # avoid accepting e.g. style parameter as command | |
|
699 | if hasattr(self, 'do_' + cmd): | |
|
700 | req.form['cmd'] = [cmd] | |
|
672 | 701 | |
|
673 | 702 | if args and args[0]: |
|
674 | 703 | node = args.pop(0) |
@@ -701,18 +730,21 b' class hgweb(object):' | |||
|
701 | 730 | if os.path.isfile(p): |
|
702 | 731 | m = p |
|
703 | 732 | |
|
704 | port = req.env["SERVER_PORT"] | |
|
705 | port = port != "80" and (":" + port) or "" | |
|
706 | uri = req.env["REQUEST_URI"] | |
|
707 | if "?" in uri: | |
|
708 | uri = uri.split("?")[0] | |
|
709 | url = "http://%s%s%s" % (req.env["SERVER_NAME"], port, uri) | |
|
733 | if not req.url: | |
|
734 | port = req.env["SERVER_PORT"] | |
|
735 | port = port != "80" and (":" + port) or "" | |
|
736 | uri = req.env["REQUEST_URI"] | |
|
737 | if "?" in uri: | |
|
738 | uri = uri.split("?")[0] | |
|
739 | req.url = "http://%s%s%s" % (req.env["SERVER_NAME"], port, uri) | |
|
740 | ||
|
710 | 741 | if not self.reponame: |
|
711 | 742 | self.reponame = (self.repo.ui.config("web", "name") |
|
712 |
or |
|
|
743 | or req.env.get('REPO_NAME') | |
|
744 | or req.url.strip('/') or self.repo.root) | |
|
713 | 745 | |
|
714 | 746 | self.t = templater.templater(m, templater.common_filters, |
|
715 | defaults={"url": url, | |
|
747 | defaults={"url": req.url, | |
|
716 | 748 | "repo": self.reponame, |
|
717 | 749 | "header": header, |
|
718 | 750 | "footer": footer, |
@@ -143,7 +143,12 b' class hgwebdir(object):' | |||
|
143 | 143 | yield row |
|
144 | 144 | |
|
145 | 145 | virtual = req.env.get("PATH_INFO", "").strip('/') |
|
146 | if virtual: | |
|
146 | if virtual.startswith('static/'): | |
|
147 | static = os.path.join(templater.templatepath(), 'static') | |
|
148 | fname = virtual[7:] | |
|
149 | req.write(staticfile(static, fname, req) or | |
|
150 | tmpl('error', error='%r not found' % fname)) | |
|
151 | elif virtual: | |
|
147 | 152 | while virtual: |
|
148 | 153 | real = dict(self.repos).get(virtual) |
|
149 | 154 | if real: |
@@ -71,7 +71,7 b' class _hgwebhandler(object, BaseHTTPServ' | |||
|
71 | 71 | env['REQUEST_METHOD'] = self.command |
|
72 | 72 | env['SERVER_NAME'] = self.server.server_name |
|
73 | 73 | env['SERVER_PORT'] = str(self.server.server_port) |
|
74 |
env['REQUEST_URI'] = |
|
|
74 | env['REQUEST_URI'] = self.path | |
|
75 | 75 | env['PATH_INFO'] = path_info |
|
76 | 76 | if query: |
|
77 | 77 | env['QUERY_STRING'] = query |
General Comments 0
You need to be logged in to leave comments.
Login now