'Check Origin for cross-site API requests.
Copied from WebSocket with changes:
- allow unspecified host/referer (e.g. scripts)'

def check_referer(self):

    host = self.request.headers.get('Host')
    referer = self.request.headers.get('Referer')
    if (not host):
        self.log.warning('Blocking    API    request    with    no    host')
        return False
    if (not referer):
        self.log.warning('Blocking    API    request    with    no    referer')
        return False
    host_path = url_path_join(host, self.hub.base_url)
    referer_path = referer.split('://', 1)[(-1)]
    if (not (referer_path + '/').startswith(host_path)):
        self.log.warning('Blocking    Cross    Origin    API    request.        Referer:    %s,    Host:    %s', referer, host_path)
        return False
    return True
