Show More
@@ -124,7 +124,7 b' class CurlSession(object):' | |||||
124 | # TODO: johbo: I did test with 7.19 of libcurl. This version has |
|
124 | # TODO: johbo: I did test with 7.19 of libcurl. This version has | |
125 | # trouble with 100 - continue being set in the expect header. This |
|
125 | # trouble with 100 - continue being set in the expect header. This | |
126 | # can lead to massive performance drops, switching it off here. |
|
126 | # can lead to massive performance drops, switching it off here. | |
127 | curl.setopt(curl.HTTPHEADER, ["Expect:"]) |
|
127 | ||
128 | curl.setopt(curl.TCP_NODELAY, True) |
|
128 | curl.setopt(curl.TCP_NODELAY, True) | |
129 | curl.setopt(curl.PROTOCOLS, curl.PROTO_HTTP) |
|
129 | curl.setopt(curl.PROTOCOLS, curl.PROTO_HTTP) | |
130 | curl.setopt(curl.USERAGENT, 'RhodeCode HTTP {}'.format(rhodecode.__version__)) |
|
130 | curl.setopt(curl.USERAGENT, 'RhodeCode HTTP {}'.format(rhodecode.__version__)) | |
@@ -132,7 +132,10 b' class CurlSession(object):' | |||||
132 | curl.setopt(curl.SSL_VERIFYHOST, 0) |
|
132 | curl.setopt(curl.SSL_VERIFYHOST, 0) | |
133 | self._curl = curl |
|
133 | self._curl = curl | |
134 |
|
134 | |||
135 | def post(self, url, data, allow_redirects=False): |
|
135 | def post(self, url, data, allow_redirects=False, headers=None): | |
|
136 | headers = headers or {} | |||
|
137 | # format is ['header_name1: header_value1', 'header_name2: header_value2']) | |||
|
138 | headers_list = ["Expect:"] + ['{}: {}'.format(k, v) for k, v in headers.items()] | |||
136 | response_buffer = StringIO() |
|
139 | response_buffer = StringIO() | |
137 |
|
140 | |||
138 | curl = self._curl |
|
141 | curl = self._curl | |
@@ -141,6 +144,7 b' class CurlSession(object):' | |||||
141 | curl.setopt(curl.POSTFIELDS, data) |
|
144 | curl.setopt(curl.POSTFIELDS, data) | |
142 | curl.setopt(curl.FOLLOWLOCATION, allow_redirects) |
|
145 | curl.setopt(curl.FOLLOWLOCATION, allow_redirects) | |
143 | curl.setopt(curl.WRITEDATA, response_buffer) |
|
146 | curl.setopt(curl.WRITEDATA, response_buffer) | |
|
147 | curl.setopt(curl.HTTPHEADER, headers_list) | |||
144 | curl.perform() |
|
148 | curl.perform() | |
145 |
|
149 | |||
146 | status_code = curl.getinfo(pycurl.HTTP_CODE) |
|
150 | status_code = curl.getinfo(pycurl.HTTP_CODE) |
@@ -56,7 +56,11 b' EXCEPTIONS_MAP = {' | |||||
56 |
|
56 | |||
57 | def _remote_call(url, payload, exceptions_map, session): |
|
57 | def _remote_call(url, payload, exceptions_map, session): | |
58 | try: |
|
58 | try: | |
59 | response = session.post(url, data=msgpack.packb(payload)) |
|
59 | headers = { | |
|
60 | 'X-RC-Method': payload.get('method'), | |||
|
61 | 'X-RC-Repo-Name': payload.get('_repo_name') | |||
|
62 | } | |||
|
63 | response = session.post(url, data=msgpack.packb(payload), headers=headers) | |||
60 | except pycurl.error as e: |
|
64 | except pycurl.error as e: | |
61 | msg = '{}. \npycurl traceback: {}'.format(e, traceback.format_exc()) |
|
65 | msg = '{}. \npycurl traceback: {}'.format(e, traceback.format_exc()) | |
62 | raise exceptions.HttpVCSCommunicationError(msg) |
|
66 | raise exceptions.HttpVCSCommunicationError(msg) | |
@@ -188,13 +192,16 b' class RemoteRepo(object):' | |||||
188 | self._session = remote_maker._session_factory() |
|
192 | self._session = remote_maker._session_factory() | |
189 |
|
193 | |||
190 | cache_repo_id = self._repo_id_sanitizer(repo_id) |
|
194 | cache_repo_id = self._repo_id_sanitizer(repo_id) | |
|
195 | _repo_name = self._get_repo_name(config, path) | |||
191 | self._cache_region, self._cache_namespace = \ |
|
196 | self._cache_region, self._cache_namespace = \ | |
192 | remote_maker.init_cache_region(cache_repo_id) |
|
197 | remote_maker.init_cache_region(cache_repo_id) | |
193 |
|
198 | |||
194 | with_wire = with_wire or {} |
|
199 | with_wire = with_wire or {} | |
195 |
|
200 | |||
196 | repo_state_uid = with_wire.get('repo_state_uid') or 'state' |
|
201 | repo_state_uid = with_wire.get('repo_state_uid') or 'state' | |
|
202 | ||||
197 | self._wire = { |
|
203 | self._wire = { | |
|
204 | "_repo_name": _repo_name, | |||
198 | "path": path, # repo path |
|
205 | "path": path, # repo path | |
199 | "repo_id": repo_id, |
|
206 | "repo_id": repo_id, | |
200 | "cache_repo_id": cache_repo_id, |
|
207 | "cache_repo_id": cache_repo_id, | |
@@ -213,6 +220,10 b' class RemoteRepo(object):' | |||||
213 |
|
220 | |||
214 | self.cert_dir = get_cert_path(rhodecode.CONFIG.get('__file__')) |
|
221 | self.cert_dir = get_cert_path(rhodecode.CONFIG.get('__file__')) | |
215 |
|
222 | |||
|
223 | def _get_repo_name(self, config, path): | |||
|
224 | repo_store = config.get('paths', '/') | |||
|
225 | return path.split(repo_store)[-1].lstrip('/') | |||
|
226 | ||||
216 | def _repo_id_sanitizer(self, repo_id): |
|
227 | def _repo_id_sanitizer(self, repo_id): | |
217 | pathless = repo_id.replace('/', '__').replace('-', '_') |
|
228 | pathless = repo_id.replace('/', '__').replace('-', '_') | |
218 | return ''.join(char if ord(char) < 128 else '_{}_'.format(ord(char)) for char in pathless) |
|
229 | return ''.join(char if ord(char) < 128 else '_{}_'.format(ord(char)) for char in pathless) | |
@@ -238,6 +249,7 b' class RemoteRepo(object):' | |||||
238 | payload = { |
|
249 | payload = { | |
239 | 'id': str(uuid.uuid4()), |
|
250 | 'id': str(uuid.uuid4()), | |
240 | 'method': name, |
|
251 | 'method': name, | |
|
252 | "_repo_name": wire['_repo_name'], | |||
241 | 'params': {'wire': wire, 'args': args, 'kwargs': kwargs} |
|
253 | 'params': {'wire': wire, 'args': args, 'kwargs': kwargs} | |
242 | } |
|
254 | } | |
243 |
|
255 |
@@ -100,7 +100,8 b' def test_repo_maker_uses_session_for_cla' | |||||
100 | 'server_and_port', 'endpoint', 'test_dummy_scm', stub_session_factory) |
|
100 | 'server_and_port', 'endpoint', 'test_dummy_scm', stub_session_factory) | |
101 | repo_maker.example_call() |
|
101 | repo_maker.example_call() | |
102 | stub_session_factory().post.assert_called_with( |
|
102 | stub_session_factory().post.assert_called_with( | |
103 |
'http://server_and_port/endpoint', data=mock.ANY |
|
103 | 'http://server_and_port/endpoint', data=mock.ANY, | |
|
104 | headers={'X-RC-Method': 'example_call', 'X-RC-Repo-Name': None}) | |||
104 |
|
105 | |||
105 |
|
106 | |||
106 | def test_repo_maker_uses_session_for_instance_methods( |
|
107 | def test_repo_maker_uses_session_for_instance_methods( | |
@@ -110,7 +111,8 b' def test_repo_maker_uses_session_for_ins' | |||||
110 | repo = repo_maker('stub_path', 'stub_repo_id', config) |
|
111 | repo = repo_maker('stub_path', 'stub_repo_id', config) | |
111 | repo.example_call() |
|
112 | repo.example_call() | |
112 | stub_session_factory().post.assert_called_with( |
|
113 | stub_session_factory().post.assert_called_with( | |
113 |
'http://server_and_port/endpoint', data=mock.ANY |
|
114 | 'http://server_and_port/endpoint', data=mock.ANY, | |
|
115 | headers={'X-RC-Method': 'example_call', 'X-RC-Repo-Name': 'stub_path'}) | |||
114 |
|
116 | |||
115 |
|
117 | |||
116 | @mock.patch('rhodecode.lib.vcs.client_http.ThreadlocalSessionFactory') |
|
118 | @mock.patch('rhodecode.lib.vcs.client_http.ThreadlocalSessionFactory') |
General Comments 0
You need to be logged in to leave comments.
Login now