apple / swift-openapi-urlsession

URLSession transport for Swift OpenAPI Generator.
https://swiftpackageindex.com/apple/swift-openapi-urlsession/documentation
Apache License 2.0
160 stars 29 forks source link

Add support for streaming on recent Darwin platforms #24

Closed simonjbeaumont closed 10 months ago

simonjbeaumont commented 10 months ago

Motivation

Recently, the ClientTransport protocol was updated to be in terms of HTTPBody, which is an AsyncSequence<ArraySlice<UInt8>>. Until now, the URLSession transport has buffered the request and response bodies in memory. This PR seeks to bring streaming support to recent Darwin platforms.

Modifications

On new enough Darwin platforms[^1], use URLSession delegate to perform bidirectional streaming with backpressure. Request body backpressure is provided by the use of StreamDelegate with a bound stream pair. Response body backpressure is provided by the use of AsyncBackpressuredStream which allows for a high and low watermark to suspend and resume the URLSession task.

[^1]: macOS 12, iOS 15, tvOS 15, watchOS 8

In more detail:

Result

Test Plan

However, it's worth noting that our CI only runs on Linux, so we won't be testing the majority of this new feature in CI.