Esempio n. 1
0
    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,
            )
Esempio n. 2
0
 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)
Esempio n. 3
0
 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,
         )
Esempio n. 4
0
 def _apply_static_route(self, web: Web, route: FutureStaticRoute,
                         url_prefix: Optional[str]) -> None:
     uri = self._url_with_prefix(route.uri, url_prefix)
     web.add_static(uri, route.file_or_directory)
Esempio n. 5
0
 def _apply_static_route(self, web: Web, route: FutureStaticRoute,
                         url_prefix: Optional[str]) -> None:
     uri = url_prefix + route.uri if url_prefix else route.uri
     web.add_static(uri, route.file_or_directory)