Expose CONNECT response headers when using a proxy
- 主要语言
- Python
- 星标
- 16.5k
- 派生
- 2.4k
- 平均合并
- 17 小时 22 分钟
- 30 天内合并 PR
- 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 还没有评估数据。