Show More
@@ -28,7 +28,7 b' import msgpack' | |||
|
28 | 28 | import dataclasses |
|
29 | 29 | import pygit2 |
|
30 | 30 | |
|
31 | from http.client import HTTPConnection | |
|
31 | import http.client | |
|
32 | 32 | |
|
33 | 33 | |
|
34 | 34 | import mercurial.scmutil |
@@ -49,24 +49,33 b' class HooksHttpClient(object):' | |||
|
49 | 49 | def __init__(self, hooks_uri): |
|
50 | 50 | self.hooks_uri = hooks_uri |
|
51 | 51 | |
|
52 | def __repr__(self): | |
|
53 | return f'{self.__class__}(hook_uri={self.hooks_uri}, proto={self.proto})' | |
|
54 | ||
|
52 | 55 | def __call__(self, method, extras): |
|
53 | connection = HTTPConnection(self.hooks_uri) | |
|
56 | connection = http.client.HTTPConnection(self.hooks_uri) | |
|
54 | 57 | # binary msgpack body |
|
55 | 58 | headers, body = self._serialize(method, extras) |
|
56 | try: | |
|
57 | connection.request('POST', '/', body, headers) | |
|
58 | except Exception as error: | |
|
59 | log.error('Hooks calling Connection failed on %s, org error: %s', connection.__dict__, error) | |
|
60 | raise | |
|
61 | response = connection.getresponse() | |
|
59 | log.debug('Doing a new hooks call using HTTPConnection to %s', self.hooks_uri) | |
|
60 | ||
|
62 | 61 | try: |
|
63 | return msgpack.load(response) | |
|
64 | except Exception: | |
|
65 | response_data = response.read() | |
|
66 | log.exception('Failed to decode hook response json data. ' | |
|
67 | 'response_code:%s, raw_data:%s', | |
|
68 | response.status, response_data) | |
|
69 | raise | |
|
62 | try: | |
|
63 | connection.request('POST', '/', body, headers) | |
|
64 | except Exception as error: | |
|
65 | log.error('Hooks calling Connection failed on %s, org error: %s', connection.__dict__, error) | |
|
66 | raise | |
|
67 | ||
|
68 | response = connection.getresponse() | |
|
69 | try: | |
|
70 | return msgpack.load(response) | |
|
71 | except Exception: | |
|
72 | response_data = response.read() | |
|
73 | log.exception('Failed to decode hook response json data. ' | |
|
74 | 'response_code:%s, raw_data:%s', | |
|
75 | response.status, response_data) | |
|
76 | raise | |
|
77 | finally: | |
|
78 | connection.close() | |
|
70 | 79 | |
|
71 | 80 | @classmethod |
|
72 | 81 | def _serialize(cls, hook_name, extras): |
@@ -75,7 +84,8 b' class HooksHttpClient(object):' | |||
|
75 | 84 | 'extras': extras |
|
76 | 85 | } |
|
77 | 86 | headers = { |
|
78 |
|
|
|
87 | "rc-hooks-protocol": cls.proto, | |
|
88 | "Connection": "keep-alive" | |
|
79 | 89 | } |
|
80 | 90 | return headers, msgpack.packb(data) |
|
81 | 91 |
General Comments 0
You need to be logged in to leave comments.
Login now