# HG changeset patch # User RhodeCode Admin # Date 2024-11-08 15:17:03 # Node ID faa7b2f44d3af9ad28c1586e976bae71980c519a # Parent b54074868bf202f4bbee0e5a393732a06414299c fix(mercurial): fixed httppostargs logic diff --git a/rhodecode/lib/middleware/simplehg.py b/rhodecode/lib/middleware/simplehg.py --- a/rhodecode/lib/middleware/simplehg.py +++ b/rhodecode/lib/middleware/simplehg.py @@ -22,6 +22,7 @@ SimpleHG middleware for handling mercuri (push/clone etc.). It's implemented with basic auth function """ +import copy import logging import urllib.parse import urllib.request @@ -32,6 +33,7 @@ from rhodecode.lib import utils from rhodecode.lib.ext_json import json from rhodecode.lib.middleware import simplevcs from rhodecode.lib.middleware.utils import get_path_info +from rhodecode.lib.str_utils import safe_str log = logging.getLogger(__name__) @@ -95,7 +97,7 @@ class SimpleHg(simplevcs.SimpleVCS): i = 1 chunks = [] # gather chunks stored in multiple 'hgarg_N' while True: - head = environ.get('HTTP_X_HGARG_{}'.format(i)) + head = environ.get(f'HTTP_X_HGARG_{i}') if not head: break i += 1 @@ -118,8 +120,18 @@ class SimpleHg(simplevcs.SimpleVCS): """ default = 'push' batch_cmds = [] + try: - cmds = cls._get_xarg_headers(environ) + httppostargs_enabled = True + post_args_size = environ.get('HTTP_X_HGARGS_POST') + if post_args_size and httppostargs_enabled: + # a new proto when httppostargs is enabled + response_data = copy.copy(environ['wsgi.input']) + cmds = [safe_str(response_data.read(post_args_size))] + else: + # old way... from headers + cmds = cls._get_xarg_headers(environ) + for pair in cmds: parts = pair.split(' ', 1) if len(parts) != 2: