From 1f542f99c0042addac01b4edbb0da5e9abfa2115 Mon Sep 17 00:00:00 2001 From: Marcin Kuzminski Date: Fri, 10 Feb 2017 16:25:06 +0100 Subject: [PATCH] http-proto: in case incoming requests come in as chunked stream the data to VCSServer. This should solve a problem of uploading large files to rhodecode. In case of git with small postBuffers GIT client streams data to the server. In such case we want to stream the data back again to vcsserver without reading it fully inside RhodeCode. --- rhodecode/lib/middleware/utils/scm_app_http.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rhodecode/lib/middleware/utils/scm_app_http.py b/rhodecode/lib/middleware/utils/scm_app_http.py index 6b2137d8..ad88ff69 100644 --- a/rhodecode/lib/middleware/utils/scm_app_http.py +++ b/rhodecode/lib/middleware/utils/scm_app_http.py @@ -93,7 +93,6 @@ class VcsHttpProxy(object): 'X-RC-Locked-Status-Code': rhodecode.CONFIG.get('lock_ret_code') }) - data = environ['wsgi.input'].read() method = environ['REQUEST_METHOD'] # Preserve the query string @@ -104,7 +103,7 @@ class VcsHttpProxy(object): response = session.request( method, url, - data=data, + data=_maybe_stream_request(environ), headers=request_headers, stream=True) @@ -120,10 +119,17 @@ class VcsHttpProxy(object): reason_phrase=response.reason) start_response(status, response_headers) - return _maybe_stream(response) + return _maybe_stream_response(response) -def _maybe_stream(response): +def _maybe_stream_request(environ): + if environ.get('HTTP_TRANSFER_ENCODING', '') == 'chunked': + return environ['wsgi.input'] + else: + return environ['wsgi.input'].read() + + +def _maybe_stream_response(response): """ Try to generate chunks from the response if it is chunked. """