aio-libs / aio-libs/aiohttp

Expose CONNECT response headers when using a proxy

Abierto
#6,078 2 comentarios 4 reacciones 0 asignados Ver en GitHub
enhancement
Lenguaje dominante
Python
Estrellas
16.5k
Forks
2.4k
Merge medio
17 h 22 min
PR fusionados (30 d)
212

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.