# HG changeset patch # User RhodeCode Admin # Date 2023-03-27 12:57:09 # Node ID beb1039e950d626bf98ff52e6974c5c274c5a0df # Parent 8dff4d0fa76a5a8d78d4ee15492318b6910050cb http-traffic: mostly use payload from encoded msgpack single header instead of multiple ones. - headers are not good for handling str/bytes we we store all info in a single b64 field diff --git a/vcsserver/http_main.py b/vcsserver/http_main.py --- a/vcsserver/http_main.py +++ b/vcsserver/http_main.py @@ -229,6 +229,7 @@ class HTTPApplication(object): self.config = Configurator(settings=settings) # Init our statsd at very start self.config.registry.statsd = StatsdClient.statsd + self.config.registry.vcs_call_context = {} self.global_config = global_config self.config.include('vcsserver.lib.rc_cache') @@ -326,6 +327,11 @@ class HTTPApplication(object): kwargs = params.get('kwargs') context_uid = None + request.registry.vcs_call_context = { + 'method': method, + 'repo_name': payload.get('_repo_name') + } + if wire: try: wire['context'] = context_uid = uuid.UUID(wire['context']) @@ -556,16 +562,19 @@ class HTTPApplication(object): @wsgiapp def _hg_stream(environ, start_response): log.debug('http-app: handling hg stream') - repo_path = environ['HTTP_X_RC_REPO_PATH'] - repo_name = environ['HTTP_X_RC_REPO_NAME'] - packed_config = base64.b64decode( - environ['HTTP_X_RC_REPO_CONFIG']) - config = msgpack.unpackb(packed_config) + + packed_cc = base64.b64decode(environ['HTTP_X_RC_VCS_STREAM_CALL_CONTEXT']) + call_context = msgpack.unpackb(packed_cc) + + repo_path = call_context['repo_path'] + repo_name = call_context['repo_name'] + config = call_context['repo_config'] + app = scm_app.create_hg_wsgi_app( repo_path, repo_name, config) # Consistent path information for hgweb - environ['PATH_INFO'] = environ['HTTP_X_RC_PATH_INFO'] + environ['PATH_INFO'] = call_context['path_info'] environ['REPO_NAME'] = repo_name self.set_env_from_config(environ, config) @@ -585,13 +594,15 @@ class HTTPApplication(object): @wsgiapp def _git_stream(environ, start_response): log.debug('http-app: handling git stream') - repo_path = environ['HTTP_X_RC_REPO_PATH'] - repo_name = environ['HTTP_X_RC_REPO_NAME'] - packed_config = base64.b64decode( - environ['HTTP_X_RC_REPO_CONFIG']) - config = msgpack.unpackb(packed_config) + + packed_cc = base64.b64decode(environ['HTTP_X_RC_VCS_STREAM_CALL_CONTEXT']) + call_context = msgpack.unpackb(packed_cc) - environ['PATH_INFO'] = environ['HTTP_X_RC_PATH_INFO'] + repo_path = call_context['repo_path'] + repo_name = call_context['repo_name'] + config = call_context['repo_config'] + + environ['PATH_INFO'] = call_context['path_info'] self.set_env_from_config(environ, config) content_type = environ.get('CONTENT_TYPE', '') diff --git a/vcsserver/tweens/request_wrapper.py b/vcsserver/tweens/request_wrapper.py --- a/vcsserver/tweens/request_wrapper.py +++ b/vcsserver/tweens/request_wrapper.py @@ -18,6 +18,8 @@ import time import logging +import msgpack + import vcsserver from vcsserver.str_utils import safe_str, ascii_str @@ -33,12 +35,15 @@ def get_user_agent(environ): return environ.get('HTTP_USER_AGENT') -def get_vcs_method(environ): - return environ.get('HTTP_X_RC_METHOD') +def get_call_context(registry) -> dict: + cc = {} + if hasattr(registry, 'vcs_call_context'): + cc.update({ + 'X-RC-Method': registry.vcs_call_context.get('method'), + 'X-RC-Repo-Name': registry.vcs_call_context.get('repo_name') + }) - -def get_vcs_repo(environ): - return environ.get('HTTP_X_RC_REPO_NAME') + return cc class RequestWrapperTween(object): @@ -53,23 +58,26 @@ class RequestWrapperTween(object): log.debug('Starting request time measurement') response = None - ua = get_user_agent(request.environ) - vcs_method = get_vcs_method(request.environ) - repo_name = get_vcs_repo(request.environ) - try: response = self.handler(request) finally: + ua = get_user_agent(request.environ) + call_context = get_call_context(request.registry) + vcs_method = call_context.get('X-RC-Method', '_NO_VCS_METHOD') + repo_name = call_context.get('X-RC-Repo-Name', '') + count = request.request_count() _ver_ = ascii_str(vcsserver.__version__) _path = safe_str(get_access_path(request.environ)) + ip = '127.0.0.1' match_route = request.matched_route.name if request.matched_route else "NOT_FOUND" resp_code = getattr(response, 'status_code', 'UNDEFINED') + _view_path = f"{repo_name}@{_path}/{vcs_method}" + total = time.time() - start - _view_path = f"{repo_name}@{_path}/{vcs_method}" log.info( 'Req[%4s] IP: %s %s Request to %s time: %.4fs [%s], VCSServer %s', count, ip, request.environ.get('REQUEST_METHOD'),