'Returns True if the referring URL is the same domain as the current request.'

def is_internal_request(self, domain, referer):

    return bool(re.match(('^https?://%s/' % re.escape(domain)), referer))
