async def route_req(self, table_name: str, key: K, web: Web, request: Request) -> Response: """Route request to worker having key in table. Arguments: table_name: Name of the table. key: The key that we want. web: The currently sued web driver, request: The web request currently being served. """ app = self.app try: dest_url: URL = app.router.key_store(table_name, key) except KeyError: raise ServiceUnavailable() dest_ident = (host, port) = self._urlident(dest_url) if dest_ident == self._urlident(app.conf.canonical_url): raise SameNode() routed_url = request.url.with_host(host).with_port(int(port)) async with app.http_client.get(routed_url) as response: return web.text( await response.text(), content_type=response.content_type, status=response.status, )
async def route_req(self, table_name: str, key: K, web: Web, request: Request) -> Response: app = self.app dest_url: URL = app.router.key_store(table_name, key) dest_ident = (host, port) = self._urlident(dest_url) if dest_ident == self._urlident(app.conf.canonical_url): raise SameNode() routed_url = request.url.with_host(host).with_port(int(port)) async with app.http_client.get(routed_url) as response: return web.text(await response.text(), content_type=response.content_type)
async def _route_req(self, dest_url: URL, web: Web, request: Request) -> Response: app = self.app dest_ident = (host, port) = self._urlident(dest_url) if dest_ident == self._urlident(app.conf.canonical_url): raise SameNode() routed_url = request.url.with_host(host).with_port(int(port)) async with app.http_client.request(request.method, routed_url) as response: return web.text( await response.text(), content_type=response.content_type, status=response.status, )