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,19 +70,30 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']) | |
75 | body = self.rfile.read(length).decode('utf-8') |
|
77 | hooks_proto = self.headers.get('rc-hooks-protocol') or 'json.v1' | |
76 | data = json.loads(body) |
|
78 | if hooks_proto == 'msgpack.v1': | |
77 | return data['method'], data['extras'] |
|
79 | # support for new vcsserver msgpack based protocol hooks | |
|
80 | data = msgpack.unpackb(self.rfile.read(length), raw=False) | |||
|
81 | else: | |||
|
82 | body = self.rfile.read(length).decode('utf-8') | |||
|
83 | data = json.loads(body) | |||
|
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) | |
81 | self.send_header("Content-type", "text/json") |
|
89 | if hooks_proto == 'msgpack.v1': | |
82 | self.end_headers() |
|
90 | self.send_header("Content-type", "application/msgpack") | |
83 | self.wfile.write(json.dumps(result)) |
|
91 | self.end_headers() | |
|
92 | self.wfile.write(msgpack.packb(result)) | |||
|
93 | else: | |||
|
94 | self.send_header("Content-type", "text/json") | |||
|
95 | self.end_headers() | |||
|
96 | self.wfile.write(json.dumps(result)) | |||
84 |
|
97 | |||
85 | def _call_hook_method(self, hooks, method, extras): |
|
98 | def _call_hook_method(self, hooks, method, extras): | |
86 | try: |
|
99 | try: |
General Comments 0
You need to be logged in to leave comments.
Login now