Esempio n. 1
0
 async def test_not_found(self):
     async with rproxy(
             self,
             self.UPSTREAM_PATH,
             subdomain=self.PROXY_SUBDOMAIN,
             path=self.PROXY_PATH,
     ) as rctx, aiohttp.ClientSession() as session:
         url = "http://%s.%s:%d%s" % (
             self.PROXY_SUBDOMAIN + ".not.found",
             self.TEST_ADDRESS,
             rctx.port,
             self.PROXY_PATH,
         )
         LOGGER.debug("rproxy url: %s", url)
         async with session.get(url) as resp:
             self.assertEqual(resp.status, HTTPStatus.NOT_FOUND)
Esempio n. 2
0
 async def test_path_joined(self):
     async with rproxy(
             self,
             self.UPSTREAM_PATH,
             subdomain=self.PROXY_SUBDOMAIN,
             path=self.PROXY_PATH,
     ) as rctx, aiohttp.ClientSession() as session:
         url = "http://%s.%s:%d%s" % (
             self.PROXY_SUBDOMAIN,
             self.TEST_ADDRESS,
             rctx.port,
             self.PROXY_PATH + "/test/joined",
         )
         LOGGER.debug("rproxy url: %s", url)
         async with session.get(url) as resp:
             self.assertEqual(resp.status, HTTPStatus.OK)
             text = await resp.text()
             self.assertEqual(self.UPSTREAM_PATH + "/test/joined", text)
Esempio n. 3
0
 async def test_websocket(self):
     async with rproxy(
             self,
             self.UPSTREAM_PATH,
             subdomain=self.PROXY_SUBDOMAIN,
             path=self.PROXY_PATH,
     ) as rctx, aiohttp.ClientSession() as session:
         url = "http://%s.%s:%d%s" % (
             self.PROXY_SUBDOMAIN,
             self.TEST_ADDRESS,
             rctx.port,
             self.PROXY_PATH,
         )
         LOGGER.debug("rproxy url: %s", url)
         async with aiohttp.ClientSession() as client_session:
             async with client_session.ws_connect(url) as ws:
                 await ws.send_str(self.UPSTREAM_PATH + "/test/joined")
                 async for msg in ws:
                     text = msg.data
                     self.assertEqual(self.UPSTREAM_PATH + "/test/joined",
                                      text)
                     await ws.close()
Esempio n. 4
0
 def __init__(
     self,
     parent: "ReverseProxyHandler",
     *,
     hostname: str = None,
     address: str = "127.0.0.1",
     port: int = 0,
 ) -> None:
     """
     Hostname must be set in order to resolve subdomains
     """
     self.parent = parent
     self.hostname = "localhost" if hostname is None else hostname
     self.address = address
     self.port = port
     self.upstream = {}
     self.logger = LOGGER.getChild(self.__class__.__qualname__)
Esempio n. 5
0
 def __init__(self, config: BaseConfig) -> None:
     self.config = config
     self.logger = LOGGER.getChild(self.__class__.__qualname__)