##// 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 25 import traceback
26 26 import threading
27 27 import socket
28 import random
28 import msgpack
29 29
30 30 from BaseHTTPServer import BaseHTTPRequestHandler
31 31 from SocketServer import TCPServer
@@ -45,7 +45,9 b' log = logging.getLogger(__name__)'
45 45 class HooksHttpHandler(BaseHTTPRequestHandler):
46 46
47 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 51 txn_id = getattr(self.server, 'txn_id', None)
50 52 if txn_id:
51 53 log.debug('Computing TXN_ID based on `%s`:`%s`',
@@ -68,16 +70,27 b' class HooksHttpHandler(BaseHTTPRequestHa'
68 70 'exception_traceback': exc_tb,
69 71 'exception_args': e.args
70 72 }
71 self._write_response(result)
73 self._write_response(hooks_proto, result)
72 74
73 75 def _read_request(self):
74 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 82 body = self.rfile.read(length).decode('utf-8')
76 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 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 94 self.send_header("Content-type", "text/json")
82 95 self.end_headers()
83 96 self.wfile.write(json.dumps(result))
General Comments 0
You need to be logged in to leave comments. Login now