##// END OF EJS Templates
http-traffic: mostly use payload from encoded msgpack single header instead of multiple ones....
super-admin -
r1078:beb1039e python3
parent child Browse files
Show More
@@ -229,6 +229,7 b' class HTTPApplication(object):'
229 229 self.config = Configurator(settings=settings)
230 230 # Init our statsd at very start
231 231 self.config.registry.statsd = StatsdClient.statsd
232 self.config.registry.vcs_call_context = {}
232 233
233 234 self.global_config = global_config
234 235 self.config.include('vcsserver.lib.rc_cache')
@@ -326,6 +327,11 b' class HTTPApplication(object):'
326 327 kwargs = params.get('kwargs')
327 328 context_uid = None
328 329
330 request.registry.vcs_call_context = {
331 'method': method,
332 'repo_name': payload.get('_repo_name')
333 }
334
329 335 if wire:
330 336 try:
331 337 wire['context'] = context_uid = uuid.UUID(wire['context'])
@@ -556,16 +562,19 b' class HTTPApplication(object):'
556 562 @wsgiapp
557 563 def _hg_stream(environ, start_response):
558 564 log.debug('http-app: handling hg stream')
559 repo_path = environ['HTTP_X_RC_REPO_PATH']
560 repo_name = environ['HTTP_X_RC_REPO_NAME']
561 packed_config = base64.b64decode(
562 environ['HTTP_X_RC_REPO_CONFIG'])
563 config = msgpack.unpackb(packed_config)
565
566 packed_cc = base64.b64decode(environ['HTTP_X_RC_VCS_STREAM_CALL_CONTEXT'])
567 call_context = msgpack.unpackb(packed_cc)
568
569 repo_path = call_context['repo_path']
570 repo_name = call_context['repo_name']
571 config = call_context['repo_config']
572
564 573 app = scm_app.create_hg_wsgi_app(
565 574 repo_path, repo_name, config)
566 575
567 576 # Consistent path information for hgweb
568 environ['PATH_INFO'] = environ['HTTP_X_RC_PATH_INFO']
577 environ['PATH_INFO'] = call_context['path_info']
569 578 environ['REPO_NAME'] = repo_name
570 579 self.set_env_from_config(environ, config)
571 580
@@ -585,13 +594,15 b' class HTTPApplication(object):'
585 594 @wsgiapp
586 595 def _git_stream(environ, start_response):
587 596 log.debug('http-app: handling git stream')
588 repo_path = environ['HTTP_X_RC_REPO_PATH']
589 repo_name = environ['HTTP_X_RC_REPO_NAME']
590 packed_config = base64.b64decode(
591 environ['HTTP_X_RC_REPO_CONFIG'])
592 config = msgpack.unpackb(packed_config)
597
598 packed_cc = base64.b64decode(environ['HTTP_X_RC_VCS_STREAM_CALL_CONTEXT'])
599 call_context = msgpack.unpackb(packed_cc)
593 600
594 environ['PATH_INFO'] = environ['HTTP_X_RC_PATH_INFO']
601 repo_path = call_context['repo_path']
602 repo_name = call_context['repo_name']
603 config = call_context['repo_config']
604
605 environ['PATH_INFO'] = call_context['path_info']
595 606 self.set_env_from_config(environ, config)
596 607
597 608 content_type = environ.get('CONTENT_TYPE', '')
@@ -18,6 +18,8 b''
18 18 import time
19 19 import logging
20 20
21 import msgpack
22
21 23 import vcsserver
22 24 from vcsserver.str_utils import safe_str, ascii_str
23 25
@@ -33,12 +35,15 b' def get_user_agent(environ):'
33 35 return environ.get('HTTP_USER_AGENT')
34 36
35 37
36 def get_vcs_method(environ):
37 return environ.get('HTTP_X_RC_METHOD')
38 def get_call_context(registry) -> dict:
39 cc = {}
40 if hasattr(registry, 'vcs_call_context'):
41 cc.update({
42 'X-RC-Method': registry.vcs_call_context.get('method'),
43 'X-RC-Repo-Name': registry.vcs_call_context.get('repo_name')
44 })
38 45
39
40 def get_vcs_repo(environ):
41 return environ.get('HTTP_X_RC_REPO_NAME')
46 return cc
42 47
43 48
44 49 class RequestWrapperTween(object):
@@ -53,23 +58,26 b' class RequestWrapperTween(object):'
53 58 log.debug('Starting request time measurement')
54 59 response = None
55 60
56 ua = get_user_agent(request.environ)
57 vcs_method = get_vcs_method(request.environ)
58 repo_name = get_vcs_repo(request.environ)
59
60 61 try:
61 62 response = self.handler(request)
62 63 finally:
64 ua = get_user_agent(request.environ)
65 call_context = get_call_context(request.registry)
66 vcs_method = call_context.get('X-RC-Method', '_NO_VCS_METHOD')
67 repo_name = call_context.get('X-RC-Repo-Name', '')
68
63 69 count = request.request_count()
64 70 _ver_ = ascii_str(vcsserver.__version__)
65 71 _path = safe_str(get_access_path(request.environ))
72
66 73 ip = '127.0.0.1'
67 74 match_route = request.matched_route.name if request.matched_route else "NOT_FOUND"
68 75 resp_code = getattr(response, 'status_code', 'UNDEFINED')
69 76
77 _view_path = f"{repo_name}@{_path}/{vcs_method}"
78
70 79 total = time.time() - start
71 80
72 _view_path = f"{repo_name}@{_path}/{vcs_method}"
73 81 log.info(
74 82 'Req[%4s] IP: %s %s Request to %s time: %.4fs [%s], VCSServer %s',
75 83 count, ip, request.environ.get('REQUEST_METHOD'),
General Comments 0
You need to be logged in to leave comments. Login now