aio-libs / aio-libs/aiohttp

Add custom header support to websocket client

Đang mở
#2,053 8 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement pr-available
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ả

## Feature

Websocket protocol actually supports custom headers. They are not widely used (afair you cannot access them in webbrowser JS in any reasonable way), but may be important.

I've encountered this issue while developing a WS proxy on aiohttp - proxy naturally wants to achieve best
content 'forwarding' possible.

Current state in aiohttp:

* Server side websocket handler can set headers nicely (as `WebSocketResponse` is inherited from `StreamResponse`);
* Client side `ws_connect()` can pass headers, but it is not documented;
* Websocket response (`ClientWebSocketResponse` class) doesn't allow to access them.

So, it looks like there are 2 things to do:

* Add `.headers` property to ClientWebSocketResponse
* Document `headers` kwarg to `ClientSession.ws_connect()`

**Upd** Motivational example:
Setting cookies in WS handler actually works in chrome, but cannot be proxied by aiohttp for now.

**Upd** about ws_connect
`ws_connect(headers=...)` seems to differ from other `ClientSession` methods as it does not accept list of pairs.

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.