async def add_onion_host(request: Request, call_next): response = await call_next(request) host = request.headers.get("host", "").split(":")[0] if tor_ext.TorService.onion_host and not tor_ext.is_onion(host): response.headers[ "Onion-Location"] = tor_ext.TorService.onion_host + request.url.path return response
async def add_onion_host(request: Request, call_next): response = await call_next(request) async with utils.redis.wait_for_redis(): host = request.headers.get("host", "").split(":")[0] onion_host = await tor_ext.get_data("onion_host", "") if onion_host and not tor_ext.is_onion(host): response.headers["Onion-Location"] = onion_host + request.url.path return response
def test_get_hostname(service_dir): assert not get_hostname("test") hostname = get_hostname(service_dir) assert hostname == "http://test.onion" assert is_onion(hostname)
def test_is_onion(): assert not is_onion("test.com") assert is_onion("test.onion") assert is_onion("TEST.ONION") assert not is_onion("TEST.COM")