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