'Handle a POST request from the client
Sends back an immediate success/failure response.
It then POSTS back to the client with grading results.'

@require_params('POST', 'xqueue_body', 'xqueue_header')
def do_POST(self):

    msg = 'XQueue    received    POST    request    {0}    to    path    {1}'.format(self.post_dict, self.path)
    self.log_message(msg)
    if self._is_grade_request():
        try:
            xqueue_header = json.loads(self.post_dict['xqueue_header'])
            callback_url = xqueue_header['lms_callback_url']
        except KeyError:
            error_msg = 'XQueue    received    invalid    grade    request'
            self._send_immediate_response(False, message=error_msg)
        except ValueError:
            error_msg = 'XQueue    could    not    decode    grade    request'
            self._send_immediate_response(False, message=error_msg)
        else:
            self._send_immediate_response(True)
            delayed_grade_func = (lambda : self._send_grade_response(callback_url, xqueue_header, self.post_dict['xqueue_body']))
            delay = self.server.config.get('response_delay', self.DEFAULT_RESPONSE_DELAY)
            Timer(delay, delayed_grade_func).start()
    else:
        self._send_immediate_response(False, message='Invalid    request    URL')
