aio-libs / aio-libs/aiohttp

Introduce `session.make_request()` API

Đang mở
#2,019 3 bình luận 1 reaction 1 người được giao Được @asvetlov nhận 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ả

Now we support request payload streaming in a bit reverse way: we could pass a generator as `data` parameter to `client.request()` but it makes things harder because of Reverse of Control. Handling back pressure and errors in generator are complicated.
Also sometimes people should pass semi-supported custom `request_class` for calculating custom headers etc.
Last Trailer headers support #1652 also requires some kind of callback -- which is not elegant at least.

I suggest adding new `client.make_request(url, params, headers, ...)` method.
The method returns `ClientStreamRequest` object.

The request is not started at moment of creation but has headers prepared.
User could modify them without subclassing.

The request has `.connect()` coroutine for connection negotiation (it works with proxies implicitly).
After connection established user calls `.send_headers()` coro, later `.write()` coro several times maybe, `.send_trailers()` if needed and `.write_eof()`.
`ClientStreamRequest` API should be pretty much close to `web.StreamResponse`.

All existing client API should be built around `ClientStreamRequest` calls.

I pretty sure this is viable approach that might make non-trivial usages much simpler than now.

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.