diff --git a/kallithea/controllers/api/__init__.py b/kallithea/controllers/api/__init__.py --- a/kallithea/controllers/api/__init__.py +++ b/kallithea/controllers/api/__init__.py @@ -36,10 +36,10 @@ from tg import Response, TGController, r 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 @@ class JSONRPCController(TGController): 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, []) diff --git a/kallithea/lib/base.py b/kallithea/lib/base.py --- a/kallithea/lib/base.py +++ b/kallithea/lib/base.py @@ -97,12 +97,13 @@ def _get_ip_addr(environ): 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 @@ class BaseController(TGController): 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: diff --git a/kallithea/lib/middleware/permanent_repo_url.py b/kallithea/lib/middleware/permanent_repo_url.py --- a/kallithea/lib/middleware/permanent_repo_url.py +++ b/kallithea/lib/middleware/permanent_repo_url.py @@ -21,7 +21,7 @@ middleware to handle permanent repo URLs 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 @@ class PermanentRepoUrl(object): 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 diff --git a/kallithea/lib/middleware/simplegit.py b/kallithea/lib/middleware/simplegit.py --- a/kallithea/lib/middleware/simplegit.py +++ b/kallithea/lib/middleware/simplegit.py @@ -31,7 +31,7 @@ Original author and date, and relevant c 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 @@ class SimpleGit(BaseVCSController): @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 diff --git a/kallithea/lib/middleware/simplehg.py b/kallithea/lib/middleware/simplehg.py --- a/kallithea/lib/middleware/simplehg.py +++ b/kallithea/lib/middleware/simplehg.py @@ -32,7 +32,7 @@ import logging 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 @@ class SimpleHg(BaseVCSController): 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 diff --git a/kallithea/lib/middleware/wrapper.py b/kallithea/lib/middleware/wrapper.py --- a/kallithea/lib/middleware/wrapper.py +++ b/kallithea/lib/middleware/wrapper.py @@ -29,8 +29,7 @@ Original author and date, and relevant c 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 @@ class RequestWrapper(object): 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)