Mercurial > kallithea
changeset 8068:c82ef5ec8dcd
lib: refactor _get_access_path as get_path_info
We will need it later when it gets more tricky to get the path from environ ...
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Thu, 26 Dec 2019 16:09:30 +0100 |
parents | 85e34d874a1e |
children | 4f03bd5ac2f2 |
files | kallithea/controllers/api/__init__.py kallithea/lib/base.py kallithea/lib/middleware/permanent_repo_url.py kallithea/lib/middleware/simplegit.py kallithea/lib/middleware/simplehg.py kallithea/lib/middleware/wrapper.py |
diffstat | 6 files changed, 18 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/controllers/api/__init__.py Thu Dec 26 04:05:14 2019 +0100 +++ b/kallithea/controllers/api/__init__.py Thu Dec 26 16:09:30 2019 +0100 @@ -36,10 +36,10 @@ from webob.exc import HTTPError, HTTPException from kallithea.lib.auth import AuthUser -from kallithea.lib.base import _get_access_path from kallithea.lib.base import _get_ip_addr as _get_ip +from kallithea.lib.base import get_path_info from kallithea.lib.compat import json -from kallithea.lib.utils2 import safe_str, safe_unicode +from kallithea.lib.utils2 import safe_str from kallithea.model.db import User @@ -209,7 +209,7 @@ log.info('IP: %s Request to %s time: %.3fs' % ( self._get_ip_addr(environ), - safe_unicode(_get_access_path(environ)), time.time() - start) + get_path_info(environ), time.time() - start) ) state.set_action(self._rpc_call, [])
--- a/kallithea/lib/base.py Thu Dec 26 04:05:14 2019 +0100 +++ b/kallithea/lib/base.py Thu Dec 26 16:09:30 2019 +0100 @@ -97,12 +97,13 @@ return _filter_proxy(ip) -def _get_access_path(environ): - """Return PATH_INFO from environ ... using tg.original_request if available.""" +def get_path_info(environ): + """Return unicode PATH_INFO from environ ... using tg.original_request if available. + """ org_req = environ.get('tg.original_request') if org_req is not None: environ = org_req.environ - return environ.get('PATH_INFO') + return safe_unicode(environ['PATH_INFO']) def log_in_user(user, remember, is_external_auth, ip_addr): @@ -526,7 +527,7 @@ log.info('IP: %s User: %s accessed %s', request.ip_addr, request.authuser, - safe_unicode(_get_access_path(environ)), + get_path_info(environ), ) return super(BaseController, self).__call__(environ, context) except webob.exc.HTTPException as e:
--- a/kallithea/lib/middleware/permanent_repo_url.py Thu Dec 26 04:05:14 2019 +0100 +++ b/kallithea/lib/middleware/permanent_repo_url.py Thu Dec 26 16:09:30 2019 +0100 @@ -21,7 +21,7 @@ from kallithea.lib.utils import fix_repo_id_name -from kallithea.lib.utils2 import safe_str +from kallithea.lib.utils2 import safe_str, safe_unicode class PermanentRepoUrl(object): @@ -31,7 +31,9 @@ self.config = config def __call__(self, environ, start_response): - path_info = environ['PATH_INFO'] + # Extract path_info as get_path_info does, but do it explicitly because + # we also have to do the reverse operation when patching it back in + path_info = safe_unicode(environ['PATH_INFO']) if path_info.startswith('/'): # it must path_info = '/' + safe_str(fix_repo_id_name(path_info[1:])) environ['PATH_INFO'] = path_info
--- a/kallithea/lib/middleware/simplegit.py Thu Dec 26 04:05:14 2019 +0100 +++ b/kallithea/lib/middleware/simplegit.py Thu Dec 26 16:09:30 2019 +0100 @@ -31,7 +31,7 @@ import logging import re -from kallithea.lib.base import BaseVCSController +from kallithea.lib.base import BaseVCSController, get_path_info from kallithea.lib.hooks import log_pull_action from kallithea.lib.middleware.pygrack import make_wsgi_app from kallithea.lib.utils import make_ui @@ -57,7 +57,7 @@ @classmethod def parse_request(cls, environ): - path_info = environ.get('PATH_INFO', '') + path_info = get_path_info(environ) m = GIT_PROTO_PAT.match(path_info) if m is None: return None
--- a/kallithea/lib/middleware/simplehg.py Thu Dec 26 04:05:14 2019 +0100 +++ b/kallithea/lib/middleware/simplehg.py Thu Dec 26 16:09:30 2019 +0100 @@ -32,7 +32,7 @@ import os import urllib -from kallithea.lib.base import BaseVCSController +from kallithea.lib.base import BaseVCSController, get_path_info from kallithea.lib.utils import make_ui from kallithea.lib.utils2 import safe_str, safe_unicode from kallithea.lib.vcs.utils.hgcompat import hgweb_mod @@ -99,7 +99,7 @@ http_accept = environ.get('HTTP_ACCEPT', '') if not http_accept.startswith('application/mercurial'): return None - path_info = environ.get('PATH_INFO', '') + path_info = get_path_info(environ) if not path_info.startswith('/'): # it must! return None
--- a/kallithea/lib/middleware/wrapper.py Thu Dec 26 04:05:14 2019 +0100 +++ b/kallithea/lib/middleware/wrapper.py Thu Dec 26 16:09:30 2019 +0100 @@ -29,8 +29,7 @@ import logging import time -from kallithea.lib.base import _get_access_path, _get_ip_addr -from kallithea.lib.utils2 import safe_unicode +from kallithea.lib.base import _get_ip_addr, get_path_info log = logging.getLogger(__name__) @@ -91,7 +90,7 @@ meter = Meter(start_response) description = "Request from %s for %s" % ( _get_ip_addr(environ), - safe_unicode(_get_access_path(environ)), + get_path_info(environ), ) try: result = self.application(environ, meter.start_response)