'Handle POSTS.'

@stats.Counted('frontend_request_count', fields=['http'])
@stats.Timed('frontend_request_latency', fields=['http'])
def Control(self):

    if (not master.MASTER_WATCHER.IsMaster()):
        stats.STATS.IncrementCounter('frontend_inactive_request_count', fields=['http'])
        logging.info('Request    sent    to    inactive    frontend    from    %s', self.client_address[0])
    try:
        api_version = int(cgi.parse_qs(self.path.split('?')[1])['api'][0])
    except (ValueError, KeyError, IndexError):
        api_version = 3
    with GRRHTTPServerHandler.active_counter_lock:
        GRRHTTPServerHandler.active_counter += 1
        stats.STATS.SetGaugeValue('frontend_active_count', self.active_counter, fields=['http'])
    try:
        content_length = self.headers.getheader('content-length')
        if (not content_length):
            raise IOError('No    content-length    header    provided.')
        length = int(content_length)
        request_comms = rdf_flows.ClientCommunication.FromSerializedString(self._GetPOSTData(length))
        if (not request_comms.api_version):
            request_comms.api_version = api_version
        responses_comms = rdf_flows.ClientCommunication(api_version=request_comms.api_version)
        source_ip = ipaddr.IPAddress(self.client_address[0])
        if (source_ip.version == 6):
            source_ip = (source_ip.ipv4_mapped or source_ip)
        request_comms.orig_request = rdf_flows.HttpRequest(timestamp=rdfvalue.RDFDatetime.Now().AsMicroSecondsFromEpoch(), raw_headers=utils.SmartStr(self.headers), source_ip=utils.SmartStr(source_ip))
        (source, nr_messages) = self.server.frontend.HandleMessageBundles(request_comms, responses_comms)
        log.LOGGER.LogHttpFrontendAccess(request_comms.orig_request, source=source, message_count=nr_messages)
        self.Send(responses_comms.SerializeToString())
    except communicator.UnknownClientCert:
        self.Send('Enrollment    required', status=406)
    finally:
        with GRRHTTPServerHandler.active_counter_lock:
            GRRHTTPServerHandler.active_counter -= 1
            stats.STATS.SetGaugeValue('frontend_active_count', self.active_counter, fields=['http'])
