Show More
@@ -31,7 +31,7 b' from rhodecode.lib import rc_cache' | |||
|
31 | 31 | from rhodecode.lib.middleware import simplevcs |
|
32 | 32 | from rhodecode.lib.middleware.utils import get_path_info |
|
33 | 33 | from rhodecode.lib.utils import is_valid_repo |
|
34 | from rhodecode.lib.str_utils import safe_str, safe_int | |
|
34 | from rhodecode.lib.str_utils import safe_str, safe_int, safe_bytes | |
|
35 | 35 | from rhodecode.lib.type_utils import str2bool |
|
36 | 36 | from rhodecode.lib.ext_json import json |
|
37 | 37 | from rhodecode.lib.hooks_daemon import store_txn_id_data |
@@ -51,8 +51,8 b' class SimpleSvnApp(object):' | |||
|
51 | 51 | |
|
52 | 52 | def __call__(self, environ, start_response): |
|
53 | 53 | request_headers = self._get_request_headers(environ) |
|
54 | data = environ['wsgi.input'] | |
|
55 | req_method = environ['REQUEST_METHOD'] | |
|
54 | data_io = environ['wsgi.input'] | |
|
55 | req_method: str = environ['REQUEST_METHOD'] | |
|
56 | 56 | has_content_length = 'CONTENT_LENGTH' in environ |
|
57 | 57 | |
|
58 | 58 | path_info = self._get_url( |
@@ -66,37 +66,38 b' class SimpleSvnApp(object):' | |||
|
66 | 66 | if req_method in ['MKCOL'] or has_content_length: |
|
67 | 67 | data_processed = False |
|
68 | 68 | # read chunk to check if we have txn-with-props |
|
69 | initial_data = data.read(1024) | |
|
70 | if initial_data.startswith('(create-txn-with-props'): | |
|
71 | data = initial_data + data.read() | |
|
69 | initial_data: bytes = data_io.read(1024) | |
|
70 | if initial_data.startswith(b'(create-txn-with-props'): | |
|
71 | data_io = initial_data + data_io.read() | |
|
72 | 72 | # store on-the-fly our rc_extra using svn revision properties |
|
73 | 73 | # those can be read later on in hooks executed so we have a way |
|
74 | 74 | # to pass in the data into svn hooks |
|
75 | 75 | rc_data = base64.urlsafe_b64encode(json.dumps(self.rc_extras)) |
|
76 | rc_data_len = len(rc_data) | |
|
76 | rc_data_len = str(len(rc_data)) | |
|
77 | 77 | # header defines data length, and serialized data |
|
78 |
skel = ' rc-scm-extras |
|
|
79 | data = data[:-2] + skel + '))' | |
|
78 | skel = b' rc-scm-extras %b %b' % (safe_bytes(rc_data_len), safe_bytes(rc_data)) | |
|
79 | data_io = data_io[:-2] + skel + b'))' | |
|
80 | 80 | data_processed = True |
|
81 | 81 | |
|
82 | 82 | if not data_processed: |
|
83 | 83 | # NOTE(johbo): Avoid that we end up with sending the request in chunked |
|
84 | 84 | # transfer encoding (mainly on Gunicorn). If we know the content |
|
85 | 85 | # length, then we should transfer the payload in one request. |
|
86 | data = initial_data + data.read() | |
|
86 | data_io = initial_data + data_io.read() | |
|
87 | 87 | |
|
88 | 88 | if req_method in ['GET', 'PUT'] or transfer_encoding == 'chunked': |
|
89 | # NOTE(marcink): when getting/uploading files we want to STREAM content | |
|
89 | # NOTE(marcink): when getting/uploading files, we want to STREAM content | |
|
90 | 90 | # back to the client/proxy instead of buffering it here... |
|
91 | 91 | stream = True |
|
92 | 92 | |
|
93 | 93 | stream = stream |
|
94 | 94 | log.debug('Calling SVN PROXY at `%s`, using method:%s. Stream: %s', |
|
95 | 95 | path_info, req_method, stream) |
|
96 | ||
|
96 | 97 | try: |
|
97 | 98 | response = requests.request( |
|
98 | 99 | req_method, path_info, |
|
99 | data=data, headers=request_headers, stream=stream) | |
|
100 | data=data_io, headers=request_headers, stream=stream) | |
|
100 | 101 | except requests.ConnectionError: |
|
101 | 102 | log.exception('ConnectionError occurred for endpoint %s', path_info) |
|
102 | 103 | raise |
@@ -119,9 +120,7 b' class SimpleSvnApp(object):' | |||
|
119 | 120 | port = safe_int(self.rc_extras['hooks_uri'].split(':')[-1]) |
|
120 | 121 | store_txn_id_data(txn_id, {'port': port}) |
|
121 | 122 | |
|
122 | start_response( | |
|
123 | '{} {}'.format(response.status_code, response.reason), | |
|
124 | response_headers) | |
|
123 | start_response(f'{response.status_code} {response.reason}', response_headers) | |
|
125 | 124 | return response.iter_content(chunk_size=1024) |
|
126 | 125 | |
|
127 | 126 | def _get_url(self, svn_http_server, path): |
General Comments 0
You need to be logged in to leave comments.
Login now