aio-libs / aio-libs/aiohttp

Expose CONNECT response headers when using a proxy

オープン
#6,078 コメント 2 件 リアクション 4 件 担当者 0 名 GitHub で見る
enhancement
主要言語
Python
スター
16.5k
フォーク
2.4k
平均マージ
17時間 22分
マージ済み PR(30日)
212

説明

### Is your feature request related to a problem?

When using a forward proxy, the client sends a [CONNECT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/CONNECT) request, to which you get a 200 response code, following which you make the proxied request. The AIOHTTP client however, doesn't expose the proxy's CONNECT response headers - which is often used to return debug information - as part of the final [ClientResponse](https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientResponse).

Can we?

```bash
# assumes that you've Docker setup locally
# let's start a forward proxy
$ docker run -d --name=tinyproxy -p 8888:8888 dannydirect/tinyproxy ANY

# the 'proxy-agent' CONNECT response header is visible when using curl
$ curl 'https://www.facebook.com' -x http://localhost:8888 -sSD - -k -o /dev/null
HTTP/1.0 200 Connection established
Proxy-agent: tinyproxy/1.8.4

HTTP/2 200
vary: Accept-Encoding
set-cookie: cm_j=eu; expires=Mon, 18-Oct-2021 06:31:08 GMT; Max-Age=604800; path=/; domain=.facebook.com; secure; httponly; SameSite=Strict
...

$ cat << EOF >aio.py
import asyncio
import aiohttp

async def send_request(url, proxy):
async with aiohttp.ClientSession() as session:
async with session.get(url, proxy=proxy) as resp:
print(resp)

asyncio.run(send_request('https://www.facebook.com', "http://localhost:8888"))
EOF

# assumes that you've Python3 + AIOHTTP set up locally
# CONNECT response headers are missing
$ python3 aio.py | command grep -i 'proxy-agent'
```

### Describe the solution you'd like

The ClientResponse object should have a field name proxy_headers of the type CIMultiDictProxy.

### Describe alternatives you've considered

The only way I have of getting this right now is to monkey patch TCPConnector.

### Related component

Client

### Additional context

_No response_

### Code of Conduct

- [X] I agree to follow the aio-libs Code of Conduct

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。