From 5af68377256a4aafebef7da98600f0bfd1546644 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Fri, 15 Mar 2024 15:15:31 -0700 Subject: [PATCH] Fix httpx warning about app=self.app, refs #2307 --- datasette/app.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/datasette/app.py b/datasette/app.py index 8591af6aab..c0b14fb28a 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -1934,36 +1934,52 @@ def _fix(self, path, avoid_path_rewrites=False): return path async def get(self, path, **kwargs): - async with httpx.AsyncClient(app=self.app) as client: + async with httpx.AsyncClient( + transport=httpx.ASGITransport(app=self.app) + ) as client: return await client.get(self._fix(path), **kwargs) async def options(self, path, **kwargs): - async with httpx.AsyncClient(app=self.app) as client: + async with httpx.AsyncClient( + transport=httpx.ASGITransport(app=self.app) + ) as client: return await client.options(self._fix(path), **kwargs) async def head(self, path, **kwargs): - async with httpx.AsyncClient(app=self.app) as client: + async with httpx.AsyncClient( + transport=httpx.ASGITransport(app=self.app) + ) as client: return await client.head(self._fix(path), **kwargs) async def post(self, path, **kwargs): - async with httpx.AsyncClient(app=self.app) as client: + async with httpx.AsyncClient( + transport=httpx.ASGITransport(app=self.app) + ) as client: return await client.post(self._fix(path), **kwargs) async def put(self, path, **kwargs): - async with httpx.AsyncClient(app=self.app) as client: + async with httpx.AsyncClient( + transport=httpx.ASGITransport(app=self.app) + ) as client: return await client.put(self._fix(path), **kwargs) async def patch(self, path, **kwargs): - async with httpx.AsyncClient(app=self.app) as client: + async with httpx.AsyncClient( + transport=httpx.ASGITransport(app=self.app) + ) as client: return await client.patch(self._fix(path), **kwargs) async def delete(self, path, **kwargs): - async with httpx.AsyncClient(app=self.app) as client: + async with httpx.AsyncClient( + transport=httpx.ASGITransport(app=self.app) + ) as client: return await client.delete(self._fix(path), **kwargs) async def request(self, method, path, **kwargs): avoid_path_rewrites = kwargs.pop("avoid_path_rewrites", None) - async with httpx.AsyncClient(app=self.app) as client: + async with httpx.AsyncClient( + transport=httpx.ASGITransport(app=self.app) + ) as client: return await client.request( method, self._fix(path, avoid_path_rewrites), **kwargs )