'Sends request to cloud service server and return the response.'

def perform_request(self, request):

    connection = self.get_connection(request)
    try:
        connection.putrequest(request.method, request.path)
        self.send_request_headers(connection, request.headers)
        self.send_request_body(connection, request.body)
        if (DEBUG_REQUESTS and request.body):
            print 'request:'
            try:
                print request.body
            except:
                pass
        resp = connection.getresponse()
        status = int(resp.status)
        message = resp.reason
        respheaders = resp.getheaders()
        for (i, value) in enumerate(respheaders):
            respheaders[i] = (value[0].lower(), value[1])
        respbody = None
        if (resp.length is None):
            respbody = resp.read()
        elif (resp.length > 0):
            respbody = resp.read(resp.length)
        if (DEBUG_RESPONSES and respbody):
            print 'response:'
            try:
                print respbody
            except:
                pass
        response = HTTPResponse(status, resp.reason, respheaders, respbody)
        if (status == 307):
            new_url = urlparse(dict(headers)['location'])
            request.host = new_url.hostname
            request.path = new_url.path
            (request.path, request.query) = self._update_request_uri_query(request)
            return self.perform_request(request)
        if (status >= 300):
            raise HTTPError(status, message, respheaders, respbody)
        return response
    finally:
        connection.close()
