# HG changeset patch # User Paul Fisher # Date 1771123194 18000 # Node ID c43ce246240b4d4745f26e2e4f91aa8a830aa1a0 # Parent 5ad58438318acac143deed537d1913c8332d7f9f Really fix content-length for real for serious. diff -r 5ad58438318a -r c43ce246240b src/git_serve/__init__.py --- a/src/git_serve/__init__.py Sat Feb 14 21:20:36 2026 -0500 +++ b/src/git_serve/__init__.py Sat Feb 14 21:39:54 2026 -0500 @@ -92,6 +92,13 @@ check_permission(req_ctx, request, b'pull') # If a request is git, we assume we should be the one handling it. cgi_env = _build_git_environ(req_ctx, request) + content_length_hdr = request.headers.get(b'content-length', b'0') + try: + content_length = int(content_length_hdr) + except ValueError as ve: + raise hgerr.InputError( + f'Invalid content-length {content_length!r}'.encode() + ) from ve http_backend = req_ctx.repo.ui.configlist( b'git-serve', b'http-backend', default=(b'git', b'http-backend') ) @@ -108,7 +115,10 @@ assert call.stdin # Git will not start writing output until stdin is fully closed. with call.stdin: - shutil.copyfileobj(request.bodyfh, call.stdin) + if content_length: + shutil.copyfileobj( + request.bodyfh, call.stdin, length=content_length + ) status, headers, rest = _parse_cgi_response(call.stdout) response.status = status @@ -190,7 +200,7 @@ # Interfacing with Mercurial -__version__ = '0.1.2' +__version__ = '0.1.3' cmdtable: dict[bytes, object] = {}