fix(mercurial): fixed httppostargs logic

This commit is contained in:
RhodeCode Admin 2024-11-08 16:17:03 +01:00
parent aa45596cef
commit 840634c16f

View file

@ -22,6 +22,7 @@ SimpleHG middleware for handling mercurial protocol request
(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: