Gracefully shut down the proxy server. Args: skip_writing_cache: If True, the proxy won't write captured exchanges to disk.
(self, skip_writing_cache: bool = False)
| 78 | return self._proxy_url |
| 79 | |
| 80 | async def stop(self, skip_writing_cache: bool = False): |
| 81 | """Gracefully shut down the proxy server. |
| 82 | |
| 83 | Args: |
| 84 | skip_writing_cache: If True, the proxy won't write captured exchanges to disk. |
| 85 | """ |
| 86 | if not self._process: |
| 87 | return |
| 88 | |
| 89 | # Send stop request to the server |
| 90 | if self._proxy_url: |
| 91 | try: |
| 92 | stop_url = f"{self._proxy_url}/stop" |
| 93 | if skip_writing_cache: |
| 94 | stop_url += "?skipWritingCache=true" |
| 95 | async with httpx.AsyncClient() as client: |
| 96 | await client.post(stop_url) |
| 97 | except Exception: |
| 98 | pass # Best effort |
| 99 | |
| 100 | # Wait for process to exit |
| 101 | self._process.wait() |
| 102 | self._process = None |
| 103 | self._proxy_url = None |
| 104 | |
| 105 | async def configure(self, file_path: str, work_dir: str): |
| 106 | """Send configuration to the proxy.""" |