# HG changeset patch # User Marcin Kuzminski # Date 2017-03-21 13:37:47 # Node ID 63143d9d489b1916d7591ecb3ffe8ba9537b4acd # Parent 8dba6b097268d7248b8a7562e0209c3f0ba40a09 git-lfs: streaming support for file upload. - ref #4235 diff --git a/rhodecode/lib/middleware/utils/scm_app_http.py b/rhodecode/lib/middleware/utils/scm_app_http.py --- a/rhodecode/lib/middleware/utils/scm_app_http.py +++ b/rhodecode/lib/middleware/utils/scm_app_http.py @@ -127,17 +127,32 @@ class VcsHttpProxy(object): def _maybe_stream_request(environ): - if environ.get('HTTP_TRANSFER_ENCODING', '') == 'chunked': + path = environ['PATH_INFO'] + stream = _is_request_chunked(environ) + log.debug('handling request `%s` with stream support: %s', path, stream) + + if stream: return environ['wsgi.input'] else: return environ['wsgi.input'].read() +def _is_request_chunked(environ): + stream = environ.get('HTTP_TRANSFER_ENCODING', '') == 'chunked' + if not stream: + # git lfs should stream for PUT requests which are upload + stream = ('git-lfs' in environ.get('HTTP_USER_AGENT', '') + and environ['REQUEST_METHOD'] == 'PUT') + return stream + + def _maybe_stream_response(response): """ Try to generate chunks from the response if it is chunked. """ - if _is_chunked(response): + stream = _is_chunked(response) + log.debug('returning response with stream: %s', stream) + if stream: return response.raw.read_chunked() else: return [response.content] diff --git a/rhodecode/tests/plugin.py b/rhodecode/tests/plugin.py --- a/rhodecode/tests/plugin.py +++ b/rhodecode/tests/plugin.py @@ -207,6 +207,8 @@ def http_environ(http_host_stub): 'SERVER_NAME': http_host_stub.split(':')[0], 'SERVER_PORT': http_host_stub.split(':')[1], 'HTTP_HOST': http_host_stub, + 'HTTP_USER_AGENT': 'rc-test-agent', + 'REQUEST_METHOD': 'GET' }