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