Mercurial > hg-git-serve
changeset 5:c43ce246240b
Really fix content-length for real for serious.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Sat, 14 Feb 2026 21:39:54 -0500 |
| parents | 5ad58438318a |
| children | 7113e0ac3662 |
| files | src/git_serve/__init__.py |
| diffstat | 1 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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] = {}
