| 341 | |
| 342 | |
| 343 | class _ScrapyProxyAgent(Agent): |
| 344 | def __init__( |
| 345 | self, |
| 346 | reactor: ReactorBase, |
| 347 | proxyURI: bytes, |
| 348 | contextFactory: IPolicyForHTTPS, |
| 349 | connectTimeout: float | None = None, |
| 350 | bindAddress: tuple[str, int] | None = None, |
| 351 | pool: HTTPConnectionPool | None = None, |
| 352 | ): |
| 353 | super().__init__( # type: ignore[no-untyped-call] |
| 354 | reactor=reactor, |
| 355 | contextFactory=contextFactory, |
| 356 | connectTimeout=connectTimeout, |
| 357 | bindAddress=bindAddress, |
| 358 | pool=pool, |
| 359 | ) |
| 360 | self._proxyURI: URI = URI.fromBytes(proxyURI) |
| 361 | |
| 362 | def request( |
| 363 | self, |
| 364 | method: bytes, |
| 365 | uri: bytes, |
| 366 | headers: TxHeaders | None = None, |
| 367 | bodyProducer: IBodyProducer | None = None, |
| 368 | ) -> Deferred[IResponse]: |
| 369 | """ |
| 370 | Issue a new request via the configured proxy. |
| 371 | """ |
| 372 | # Cache *all* connections under the same key, since we are only |
| 373 | # connecting to a single destination, the proxy: |
| 374 | return self._requestWithEndpoint( |
| 375 | key=(b"http-proxy", self._proxyURI.host, self._proxyURI.port), |
| 376 | endpoint=self._getEndpoint(self._proxyURI), # type: ignore[no-untyped-call] |
| 377 | method=method, |
| 378 | parsedURI=URI.fromBytes(uri), |
| 379 | headers=headers, |
| 380 | bodyProducer=bodyProducer, |
| 381 | requestPath=uri, |
| 382 | ) |
| 383 | |
| 384 | |
| 385 | class _ScrapyAgent: |