##// END OF EJS Templates
hooks: support v2 hooks protocol using binary msgpack
super-admin -
r4902:cae6657c default
parent child Browse files
Show More
@@ -25,7 +25,7 b' import tempfile'
25 import traceback
25 import traceback
26 import threading
26 import threading
27 import socket
27 import socket
28 import random
28 import msgpack
29
29
30 from BaseHTTPServer import BaseHTTPRequestHandler
30 from BaseHTTPServer import BaseHTTPRequestHandler
31 from SocketServer import TCPServer
31 from SocketServer import TCPServer
@@ -45,7 +45,9 b' log = logging.getLogger(__name__)'
45 class HooksHttpHandler(BaseHTTPRequestHandler):
45 class HooksHttpHandler(BaseHTTPRequestHandler):
46
46
47 def do_POST(self):
47 def do_POST(self):
48 method, extras = self._read_request()
48 hooks_proto, method, extras = self._read_request()
49 log.debug('Handling HooksHttpHandler %s with %s proto', method, hooks_proto)
50
49 txn_id = getattr(self.server, 'txn_id', None)
51 txn_id = getattr(self.server, 'txn_id', None)
50 if txn_id:
52 if txn_id:
51 log.debug('Computing TXN_ID based on `%s`:`%s`',
53 log.debug('Computing TXN_ID based on `%s`:`%s`',
@@ -68,16 +70,27 b' class HooksHttpHandler(BaseHTTPRequestHa'
68 'exception_traceback': exc_tb,
70 'exception_traceback': exc_tb,
69 'exception_args': e.args
71 'exception_args': e.args
70 }
72 }
71 self._write_response(result)
73 self._write_response(hooks_proto, result)
72
74
73 def _read_request(self):
75 def _read_request(self):
74 length = int(self.headers['Content-Length'])
76 length = int(self.headers['Content-Length'])
77 hooks_proto = self.headers.get('rc-hooks-protocol') or 'json.v1'
78 if hooks_proto == 'msgpack.v1':
79 # support for new vcsserver msgpack based protocol hooks
80 data = msgpack.unpackb(self.rfile.read(length), raw=False)
81 else:
75 body = self.rfile.read(length).decode('utf-8')
82 body = self.rfile.read(length).decode('utf-8')
76 data = json.loads(body)
83 data = json.loads(body)
77 return data['method'], data['extras']
84
85 return hooks_proto, data['method'], data['extras']
78
86
79 def _write_response(self, result):
87 def _write_response(self, hooks_proto, result):
80 self.send_response(200)
88 self.send_response(200)
89 if hooks_proto == 'msgpack.v1':
90 self.send_header("Content-type", "application/msgpack")
91 self.end_headers()
92 self.wfile.write(msgpack.packb(result))
93 else:
81 self.send_header("Content-type", "text/json")
94 self.send_header("Content-type", "text/json")
82 self.end_headers()
95 self.end_headers()
83 self.wfile.write(json.dumps(result))
96 self.wfile.write(json.dumps(result))
General Comments 0
You need to be logged in to leave comments. Login now