'Handles the HTTP POST request.
Attempts to interpret all HTTP POST requests as XML-RPC calls,
which are forwarded to the server\'s ``_dispatch`` method for
handling.'

def do_POST(self):

    if (not self.is_rpc_path_valid()):
        self.report_404()
        return
    try:
        max_chunk_size = ((10 * 1024) * 1024)
        size_remaining = int(self.headers[u'content-length'])
        L = []
        while size_remaining:
            chunk_size = min(size_remaining, max_chunk_size)
            L.append(self.rfile.read(chunk_size))
            size_remaining -= len(L[(-1)])
        data = ''.join(L)
        (params, method) = xmlrpc.loads(data)
        if (method == u'samp.webhub.register'):
            params = list(params)
            params.append(self.client_address)
            if (u'Origin' in self.headers):
                params.append(self.headers.get(u'Origin'))
            else:
                params.append(u'unknown')
            params = tuple(params)
            data = xmlrpc.dumps(params, methodname=method)
        elif (method in (u'samp.hub.notify', u'samp.hub.notifyAll', u'samp.hub.call', u'samp.hub.callAll', u'samp.hub.callAndWait')):
            user = u'unknown'
            if (method == u'samp.hub.callAndWait'):
                params[2][u'host'] = self.address_string()
                params[2][u'user'] = user
            else:
                params[(-1)][u'host'] = self.address_string()
                params[(-1)][u'user'] = user
            data = xmlrpc.dumps(params, methodname=method)
        data = self.decode_request_content(data)
        if (data is None):
            return
        response = self.server._marshaled_dispatch(data, getattr(self, u'_dispatch', None), self.path)
    except Exception as e:
        self.send_response(500)
        if (hasattr(self.server, u'_send_traceback_header') and self.server._send_traceback_header):
            self.send_header(u'X-exception', str(e))
            trace = traceback.format_exc()
            trace = str(trace.encode(u'ASCII', u'backslashreplace'), u'ASCII')
            self.send_header(u'X-traceback', trace)
        self.send_header(u'Content-length', u'0')
        self.end_headers()
    else:
        self.send_response(200)
        self.send_header(u'Content-type', u'text/xml')
        if (self.encode_threshold is not None):
            if (len(response) > self.encode_threshold):
                q = self.accept_encodings().get(u'gzip', 0)
                if q:
                    try:
                        response = xmlrpc.gzip_encode(response)
                        self.send_header(u'Content-Encoding', u'gzip')
                    except NotImplementedError:
                        pass
        self.send_header(u'Content-length', str(len(response)))
        self.end_headers()
        self.wfile.write(response)
