Let's not reinvent URL construction in a function that runs the
templater.
Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
Let's not reinvent URL construction in a function that runs the
templater.
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/hgweb/hgweb_mod.py (18 lines) |
| untrusted=untrusted) | untrusted=untrusted) | ||||
| def archivelist(self, nodeid): | def archivelist(self, nodeid): | ||||
| allowed = self.configlist('web', 'allow_archive') | allowed = self.configlist('web', 'allow_archive') | ||||
| for typ, spec in self.archivespecs.iteritems(): | for typ, spec in self.archivespecs.iteritems(): | ||||
| if typ in allowed or self.configbool('web', 'allow%s' % typ): | if typ in allowed or self.configbool('web', 'allow%s' % typ): | ||||
| yield {'type': typ, 'extension': spec[2], 'node': nodeid} | yield {'type': typ, 'extension': spec[2], 'node': nodeid} | ||||
| def templater(self, wsgireq): | def templater(self, wsgireq, req): | ||||
| # determine scheme, port and server name | # determine scheme, port and server name | ||||
| # this is needed to create absolute urls | # this is needed to create absolute urls | ||||
| proto = wsgireq.env.get('wsgi.url_scheme') | |||||
| if proto == 'https': | |||||
| proto = 'https' | |||||
| default_port = '443' | |||||
| else: | |||||
| proto = 'http' | |||||
| default_port = '80' | |||||
| port = wsgireq.env[r'SERVER_PORT'] | |||||
| port = port != default_port and (r':' + port) or r'' | |||||
| urlbase = r'%s://%s%s' % (proto, wsgireq.env[r'SERVER_NAME'], port) | |||||
| logourl = self.config('web', 'logourl') | logourl = self.config('web', 'logourl') | ||||
| logoimg = self.config('web', 'logoimg') | logoimg = self.config('web', 'logoimg') | ||||
| staticurl = (self.config('web', 'staticurl') | staticurl = (self.config('web', 'staticurl') | ||||
| or pycompat.sysbytes(wsgireq.url) + 'static/') | or pycompat.sysbytes(wsgireq.url) + 'static/') | ||||
| if not staticurl.endswith('/'): | if not staticurl.endswith('/'): | ||||
| staticurl += '/' | staticurl += '/' | ||||
| # some functions for the templater | # some functions for the templater | ||||
| # create the templater | # create the templater | ||||
| # TODO: export all keywords: defaults = templatekw.keywords.copy() | # TODO: export all keywords: defaults = templatekw.keywords.copy() | ||||
| defaults = { | defaults = { | ||||
| 'url': pycompat.sysbytes(wsgireq.url), | 'url': pycompat.sysbytes(wsgireq.url), | ||||
| 'logourl': logourl, | 'logourl': logourl, | ||||
| 'logoimg': logoimg, | 'logoimg': logoimg, | ||||
| 'staticurl': staticurl, | 'staticurl': staticurl, | ||||
| 'urlbase': urlbase, | 'urlbase': req.advertisedbaseurl, | ||||
| 'repo': self.reponame, | 'repo': self.reponame, | ||||
| 'encoding': encoding.encoding, | 'encoding': encoding.encoding, | ||||
| 'motd': motd, | 'motd': motd, | ||||
| 'sessionvars': sessionvars, | 'sessionvars': sessionvars, | ||||
| 'pathdef': makebreadcrumb(pycompat.sysbytes(wsgireq.url)), | 'pathdef': makebreadcrumb(pycompat.sysbytes(wsgireq.url)), | ||||
| 'style': style, | 'style': style, | ||||
| 'nonce': self.nonce, | 'nonce': self.nonce, | ||||
| } | } | ||||
| wsgireq.form['node'] = [fn[:-len(ext)]] | wsgireq.form['node'] = [fn[:-len(ext)]] | ||||
| wsgireq.form['type'] = [type_] | wsgireq.form['type'] = [type_] | ||||
| else: | else: | ||||
| cmd = wsgireq.form.get('cmd', [''])[0] | cmd = wsgireq.form.get('cmd', [''])[0] | ||||
| # process the web interface request | # process the web interface request | ||||
| try: | try: | ||||
| tmpl = rctx.templater(wsgireq) | tmpl = rctx.templater(wsgireq, req) | ||||
| ctype = tmpl('mimetype', encoding=encoding.encoding) | ctype = tmpl('mimetype', encoding=encoding.encoding) | ||||
| ctype = templater.stringify(ctype) | ctype = templater.stringify(ctype) | ||||
| # check read permissions non-static content | # check read permissions non-static content | ||||
| if cmd != 'static': | if cmd != 'static': | ||||
| self.check_perm(rctx, wsgireq, None) | self.check_perm(rctx, wsgireq, None) | ||||
| if cmd == '': | if cmd == '': | ||||