Show More
@@ -18,7 +18,6 b'' | |||
|
18 | 18 | import io |
|
19 | 19 | import os |
|
20 | 20 | import sys |
|
21 | import base64 | |
|
22 | 21 | import locale |
|
23 | 22 | import logging |
|
24 | 23 | import uuid |
@@ -37,11 +36,12 b' from pyramid.config import Configurator' | |||
|
37 | 36 | from pyramid.wsgi import wsgiapp |
|
38 | 37 | from pyramid.response import Response |
|
39 | 38 | |
|
40 | from vcsserver.base import BinaryEnvelope | |
|
39 | from vcsserver.base import BytesEnvelope, BinaryEnvelope | |
|
41 | 40 | from vcsserver.lib.rc_json import json |
|
42 | 41 | from vcsserver.config.settings_maker import SettingsMaker |
|
43 |
from vcsserver.str_utils import safe_int |
|
|
42 | from vcsserver.str_utils import safe_int | |
|
44 | 43 | from vcsserver.lib.statsd_client import StatsdClient |
|
44 | from vcsserver.tweens.request_wrapper import get_call_context, get_headers_call_context | |
|
45 | 45 | |
|
46 | 46 | log = logging.getLogger(__name__) |
|
47 | 47 | |
@@ -234,6 +234,7 b' class HTTPApplication(object):' | |||
|
234 | 234 | |
|
235 | 235 | self.global_config = global_config |
|
236 | 236 | self.config.include('vcsserver.lib.rc_cache') |
|
237 | self.config.include('vcsserver.lib.rc_cache.archive_cache') | |
|
237 | 238 | |
|
238 | 239 | settings_locale = settings.get('locale', '') or 'en_US.UTF-8' |
|
239 | 240 | vcs = VCS(locale_conf=settings_locale, cache_config=settings) |
@@ -330,7 +331,7 b' class HTTPApplication(object):' | |||
|
330 | 331 | |
|
331 | 332 | request.registry.vcs_call_context = { |
|
332 | 333 | 'method': method, |
|
333 | 'repo_name': payload.get('_repo_name') | |
|
334 | 'repo_name': payload.get('_repo_name'), | |
|
334 | 335 | } |
|
335 | 336 | |
|
336 | 337 | if wire: |
@@ -345,7 +346,8 b' class HTTPApplication(object):' | |||
|
345 | 346 | if log.isEnabledFor(logging.DEBUG): |
|
346 | 347 | # also we SKIP printing out any of those methods args since they maybe excessive |
|
347 | 348 | just_args_methods = { |
|
348 | 'commitctx': ('content', 'removed', 'updated') | |
|
349 | 'commitctx': ('content', 'removed', 'updated'), | |
|
350 | 'commit': ('content', 'removed', 'updated') | |
|
349 | 351 | } |
|
350 | 352 | if method in just_args_methods: |
|
351 | 353 | skip_args = just_args_methods[method] |
@@ -506,10 +508,13 b' class HTTPApplication(object):' | |||
|
506 | 508 | def _render(value, system): |
|
507 | 509 | bin_type = False |
|
508 | 510 | res = value.get('result') |
|
509 |
if |
|
|
511 | if isinstance(res, BytesEnvelope): | |
|
512 | log.debug('Result is wrapped in BytesEnvelope type') | |
|
513 | bin_type = True | |
|
514 | elif isinstance(res, BinaryEnvelope): | |
|
510 | 515 | log.debug('Result is wrapped in BinaryEnvelope type') |
|
511 |
value['result'] = res.val |
|
|
512 |
bin_type = |
|
|
516 | value['result'] = res.val | |
|
517 | bin_type = True | |
|
513 | 518 | |
|
514 | 519 | request = system.get('request') |
|
515 | 520 | if request is not None: |
@@ -573,9 +578,7 b' class HTTPApplication(object):' | |||
|
573 | 578 | @wsgiapp |
|
574 | 579 | def _hg_stream(environ, start_response): |
|
575 | 580 | log.debug('http-app: handling hg stream') |
|
576 | ||
|
577 | packed_cc = base64.b64decode(environ['HTTP_X_RC_VCS_STREAM_CALL_CONTEXT']) | |
|
578 | call_context = msgpack.unpackb(packed_cc) | |
|
581 | call_context = get_headers_call_context(environ) | |
|
579 | 582 | |
|
580 | 583 | repo_path = call_context['repo_path'] |
|
581 | 584 | repo_name = call_context['repo_name'] |
@@ -606,8 +609,7 b' class HTTPApplication(object):' | |||
|
606 | 609 | def _git_stream(environ, start_response): |
|
607 | 610 | log.debug('http-app: handling git stream') |
|
608 | 611 | |
|
609 | packed_cc = base64.b64decode(environ['HTTP_X_RC_VCS_STREAM_CALL_CONTEXT']) | |
|
610 | call_context = msgpack.unpackb(packed_cc) | |
|
612 | call_context = get_headers_call_context(environ) | |
|
611 | 613 | |
|
612 | 614 | repo_path = call_context['repo_path'] |
|
613 | 615 | repo_name = call_context['repo_name'] |
@@ -649,15 +651,18 b' class HTTPApplication(object):' | |||
|
649 | 651 | |
|
650 | 652 | def handle_vcs_exception(self, exception, request): |
|
651 | 653 | _vcs_kind = getattr(exception, '_vcs_kind', '') |
|
654 | ||
|
652 | 655 | if _vcs_kind == 'repo_locked': |
|
653 | # Get custom repo-locked status code if present. | |
|
654 |
status_code = |
|
|
656 | headers_call_context = get_headers_call_context(request.environ) | |
|
657 | status_code = safe_int(headers_call_context['locked_status_code']) | |
|
658 | ||
|
655 | 659 | return HTTPRepoLocked( |
|
656 | title=str(exception), status_code=status_code) | |
|
660 | title=str(exception), status_code=status_code, headers=[('X-Rc-Locked', '1')]) | |
|
657 | 661 | |
|
658 | 662 | elif _vcs_kind == 'repo_branch_protected': |
|
659 | 663 | # Get custom repo-branch-protected status code if present. |
|
660 |
return HTTPRepoBranchProtected( |
|
|
664 | return HTTPRepoBranchProtected( | |
|
665 | title=str(exception), headers=[('X-Rc-Branch-Protection', '1')]) | |
|
661 | 666 | |
|
662 | 667 | exc_info = request.exc_info |
|
663 | 668 | store_exception(id(exc_info), exc_info) |
@@ -767,7 +772,7 b' def main(global_config, **settings):' | |||
|
767 | 772 | pyramid_app = HTTPApplication(settings=settings, global_config=global_config).wsgi_app() |
|
768 | 773 | total_time = time.time() - start_time |
|
769 | 774 | log.info('Pyramid app `%s` created and configured in %.2fs', |
|
770 |
|
|
|
775 | pyramid_app.__class__, total_time) | |
|
771 | 776 | return pyramid_app |
|
772 | 777 | |
|
773 | 778 |
General Comments 0
You need to be logged in to leave comments.
Login now