aio-libs / aio-libs/aiohttp

Expose CONNECT response headers when using a proxy

Đang mở
#6,078 2 bình luận 4 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
Python
Star
16.5k
Fork
2.4k
Merge trung bình
17 giờ 22 phút
Pull request đã merge (30 ngày)
212

Mô tả

### 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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.