Example #1
0
def check():
    global good_app_ids_count
    while True:
        if good_app_ids_count >= 10:
            return
        appid = APP_ID_QUEUE.get()
        try:
            app_status = _goagent.gae_urlfetch(
                'GET', 'http://www.baidu.com', {}, '',
                'https://%s.appspot.com/2?' % appid).app_status
            sys.stderr.write('%s => %s\n' % (appid, app_status))
            sys.stderr.flush()
            if app_status == 200:
                if good_app_ids_count >= 10:
                    return
                print(appid)
                good_app_ids_count += 1
        except:
            sys.stderr.write(traceback.format_exc())
            sys.stderr.flush()
Example #2
0
def check():
    global good_app_ids_count
    while True:
        if good_app_ids_count >= 10:
            return
        appid = APP_ID_QUEUE.get()
        try:
            app_status = _goagent.gae_urlfetch(
                'GET', 'http://www.baidu.com', {}, '',
                'https://%s.appspot.com/2?' % appid).app_status
            sys.stderr.write('%s => %s\n' % (appid, app_status))
            sys.stderr.flush()
            if app_status == 200:
                if good_app_ids_count >= 10:
                    return
                print(appid)
                good_app_ids_count += 1
        except:
            sys.stderr.write(traceback.format_exc())
            sys.stderr.flush()
Example #3
0
def main():
    gevent.monkey.patch_all()
    good_app_ids_count = 0
    _goagent.http_util.dns_resolve = lambda *args, **kwargs: ['203.208.46.210', '203.208.46.209', '203.208.46.212']
    for appid in T1_APP_IDS + T2_APP_IDS:
        try:
            app_status = _goagent.gae_urlfetch(
                'GET', 'http://www.baidu.com', {}, '',
               'https://%s.appspot.com/2?' % appid).app_status
            sys.stderr.write('%s => %s\n' % (appid, app_status))
            sys.stderr.flush()
            if app_status == 200:
                print(appid)
                good_app_ids_count += 1
                if good_app_ids_count == 10:
                    break
        except:
            sys.stderr.write(traceback.format_exc())
            sys.stderr.flush()
    print('')
Example #4
0
def main():
    gevent.monkey.patch_all()
    good_app_ids_count = 0
    _goagent.http_util.dns_resolve = lambda *args, **kwargs: [
        '203.208.46.210', '203.208.46.209', '203.208.46.212'
    ]
    for appid in T1_APP_IDS + T2_APP_IDS:
        try:
            app_status = _goagent.gae_urlfetch(
                'GET', 'http://www.baidu.com', {}, '',
                'https://%s.appspot.com/2?' % appid).app_status
            sys.stderr.write('%s => %s\n' % (appid, app_status))
            sys.stderr.flush()
            if app_status == 200:
                print(appid)
                good_app_ids_count += 1
                if good_app_ids_count == 10:
                    break
        except:
            sys.stderr.write(traceback.format_exc())
            sys.stderr.flush()
    print('')
Example #5
0
def forward(client, proxy, appids):
    parsed_url = urllib.parse.urlparse(client.url)
    range_in_query = 'range=' in parsed_url.query
    special_range = (any(x(client.host) for x in AUTORANGE_HOSTS_MATCH) or client.url.endswith(
        AUTORANGE_ENDSWITH)) and not client.url.endswith(AUTORANGE_NOENDSWITH)
    if 'Range' in client.headers:
        m = re.search('bytes=(\d+)-', client.headers['Range'])
        start = int(m.group(1) if m else 0)
        client.headers['Range'] = 'bytes=%d-%d' % (start, start + AUTORANGE_MAXSIZE - 1)
        LOGGER.info('[%s] range found in headers: %s' % (repr(client), client.headers['Range']))
    elif not range_in_query and special_range:
        try:
            m = re.search('bytes=(\d+)-', client.headers.get('Range', ''))
            start = int(m.group(1) if m else 0)
            client.headers['Range'] = 'bytes=%d-%d' % (start, start + AUTORANGE_MAXSIZE - 1)
            LOGGER.info('[%s] auto range headers: %s' % (repr(client), client.headers['Range']))
        except StopIteration:
            pass
    response = None
    try:
        kwargs = {}
        if proxy.password:
            kwargs['password'] = proxy.password
        if proxy.validate:
            kwargs['validate'] = 1
        fetchserver = 'https://%s.appspot.com%s?' % (proxy.appid, proxy.path)
        response = _goagent.gae_urlfetch(
            client.method, client.url, client.headers, client.payload, fetchserver,
            create_tcp_socket=client.create_tcp_socket, **kwargs)
        if response is None:
            client.fall_back('urlfetch empty response')
        if response.app_status == 503:
            proxy.died = True
            client.fall_back('goagent server over quota')
        if response.app_status == 404:
            proxy.died = True
            client.fall_back('goagent server not found')
        if response.app_status == 302:
            proxy.died = True
            client.fall_back('goagent server 302 moved')
        if response.app_status != 200:
            if LOGGER.isEnabledFor(logging.DEBUG):
                LOGGER.debug('HTTP/1.1 %s\r\n%s\r\n' % (response.status, ''.join(
                    '%s: %s\r\n' % (k.title(), v) for k, v in response.getheaders() if k != 'transfer-encoding')))
                LOGGER.debug(response.read())
            client.fall_back('urlfetch failed: %s' % response.app_status)
        client.forward_started = True
        if response.status == 206:
            fetchservers = [fetchserver]
            fetchservers += ['https://%s.appspot.com/2?' % appid for appid in appids]
            rangefetch = _goagent.RangeFetch(
                client.downstream_wfile, response, client.method, client.url, client.headers, client.payload,
                fetchservers, proxy.password, maxsize=AUTORANGE_MAXSIZE, bufsize=AUTORANGE_BUFSIZE,
                waitsize=AUTORANGE_WAITSIZE, threads=AUTORANGE_THREADS, create_tcp_socket=client.create_tcp_socket)
            return rangefetch.fetch()

        if 'Set-Cookie' in response.msg:
            response.msg['Set-Cookie'] = normcookie(response.msg['Set-Cookie'])
        client.downstream_wfile.write('HTTP/1.1 %s\r\n%s\r\n' % (response.status, ''.join(
            '%s: %s\r\n' % (k.title(), v) for k, v in response.getheaders() if k != 'transfer-encoding')))
        content_length = int(response.getheader('Content-Length', 0))
        content_range = response.getheader('Content-Range', '')
        if content_range:
            start, end, length = list(map(int, re.search(r'bytes (\d+)-(\d+)/(\d+)', content_range).group(1, 2, 3)))
        else:
            start, end, length = 0, content_length-1, content_length
        while 1:
            data = response.read(8192)
            if not data:
                response.close()
                return
            start += len(data)
            client.downstream_wfile.write(data)
            if start >= end:
                response.close()
                return
    finally:
        if response:
            response.close()