Show More
@@ -648,16 +648,43 b' class hgweb(object):' | |||||
648 | def rewrite_request(req): |
|
648 | def rewrite_request(req): | |
649 | '''translate new web interface to traditional format''' |
|
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 | if req.form.has_key('cmd'): |
|
685 | if req.form.has_key('cmd'): | |
652 | # old style |
|
686 | # old style | |
653 | return |
|
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 | args = query.split('/', 2) |
|
689 | args = query.split('/', 2) | |
663 | if not args or not args[0]: |
|
690 | if not args or not args[0]: | |
@@ -668,7 +695,9 b' class hgweb(object):' | |||||
668 | if style != -1: |
|
695 | if style != -1: | |
669 | req.form['style'] = [cmd[:style]] |
|
696 | req.form['style'] = [cmd[:style]] | |
670 | cmd = cmd[style+1:] |
|
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 | if args and args[0]: |
|
702 | if args and args[0]: | |
674 | node = args.pop(0) |
|
703 | node = args.pop(0) | |
@@ -701,18 +730,21 b' class hgweb(object):' | |||||
701 | if os.path.isfile(p): |
|
730 | if os.path.isfile(p): | |
702 | m = p |
|
731 | m = p | |
703 |
|
732 | |||
704 | port = req.env["SERVER_PORT"] |
|
733 | if not req.url: | |
705 | port = port != "80" and (":" + port) or "" |
|
734 | port = req.env["SERVER_PORT"] | |
706 | uri = req.env["REQUEST_URI"] |
|
735 | port = port != "80" and (":" + port) or "" | |
707 | if "?" in uri: |
|
736 | uri = req.env["REQUEST_URI"] | |
708 | uri = uri.split("?")[0] |
|
737 | if "?" in uri: | |
709 | url = "http://%s%s%s" % (req.env["SERVER_NAME"], port, uri) |
|
738 | uri = uri.split("?")[0] | |
|
739 | req.url = "http://%s%s%s" % (req.env["SERVER_NAME"], port, uri) | |||
|
740 | ||||
710 | if not self.reponame: |
|
741 | if not self.reponame: | |
711 | self.reponame = (self.repo.ui.config("web", "name") |
|
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 | self.t = templater.templater(m, templater.common_filters, |
|
746 | self.t = templater.templater(m, templater.common_filters, | |
715 | defaults={"url": url, |
|
747 | defaults={"url": req.url, | |
716 | "repo": self.reponame, |
|
748 | "repo": self.reponame, | |
717 | "header": header, |
|
749 | "header": header, | |
718 | "footer": footer, |
|
750 | "footer": footer, |
@@ -143,7 +143,12 b' class hgwebdir(object):' | |||||
143 | yield row |
|
143 | yield row | |
144 |
|
144 | |||
145 | virtual = req.env.get("PATH_INFO", "").strip('/') |
|
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 | while virtual: |
|
152 | while virtual: | |
148 | real = dict(self.repos).get(virtual) |
|
153 | real = dict(self.repos).get(virtual) | |
149 | if real: |
|
154 | if real: |
@@ -71,7 +71,7 b' class _hgwebhandler(object, BaseHTTPServ' | |||||
71 | env['REQUEST_METHOD'] = self.command |
|
71 | env['REQUEST_METHOD'] = self.command | |
72 | env['SERVER_NAME'] = self.server.server_name |
|
72 | env['SERVER_NAME'] = self.server.server_name | |
73 | env['SERVER_PORT'] = str(self.server.server_port) |
|
73 | env['SERVER_PORT'] = str(self.server.server_port) | |
74 |
env['REQUEST_URI'] = |
|
74 | env['REQUEST_URI'] = self.path | |
75 | env['PATH_INFO'] = path_info |
|
75 | env['PATH_INFO'] = path_info | |
76 | if query: |
|
76 | if query: | |
77 | env['QUERY_STRING'] = query |
|
77 | env['QUERY_STRING'] = query |
General Comments 0
You need to be logged in to leave comments.
Login now