For some requests, I return a huge blob (Think 2-3GB). But If the browser aborts reading (E.g. tab closed), I need to cancel writing to the Response Body. /* I use version 4.73.0, as it contains
the only way I could find to make it work, as e.g. https://github.com/vapor/vapor/blob/main/Sources/Vapor/Response/Response+Body.swift#L153C1-L153C144 requires the blobs to be synchronously fetched and that is not possible with the API I use. If you know a better way please tell me, as I know it's a non-solution to just use an older version. */
Code snippet (Truncated due to reasons):
app.get("v1", "stream", ":path") { req async throws in
let file = req.parameters.get("path")!
let fileStream = findFile(file) // AsyncThrowingStream
let response = Response(
body: .init(managedAsyncStream: { writer in
for try await blob in fileStream { try await writer.write(.buffer(blob)) }
})
)
return response
}
The thing I want to do here is to have some check in my for loop to break out from it, as soon as it's no longer read from. Is that possible? Or am I trying to tackle this problem from the wrong POV?