##// END OF EJS Templates
hooks: cleanup connection
super-admin -
r1110:98ceac59 python3
parent child Browse files
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,15 +49,22 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)
59 log.debug('Doing a new hooks call using HTTPConnection to %s', self.hooks_uri)
60
61 try:
56 62 try:
57 63 connection.request('POST', '/', body, headers)
58 64 except Exception as error:
59 65 log.error('Hooks calling Connection failed on %s, org error: %s', connection.__dict__, error)
60 66 raise
67
61 68 response = connection.getresponse()
62 69 try:
63 70 return msgpack.load(response)
@@ -67,6 +74,8 b' class HooksHttpClient(object):'
67 74 'response_code:%s, raw_data:%s',
68 75 response.status, response_data)
69 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 'rc-hooks-protocol': cls.proto
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