Wait for completion of chunked body
This commit is contained in:
parent
a8cf77ec7c
commit
1550ec1298
|
@ -11,7 +11,7 @@ let package = Package(
|
||||||
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),
|
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),
|
||||||
|
|
||||||
// 🤐 Unzip archives
|
// 🤐 Unzip archives
|
||||||
.package(url: "https://github.com/microtherion/ZIPFoundation.git", .upToNextMajor(from: "0.9.9-µ2"))
|
.package(url: "https://github.com/microtherion/ZIPFoundation.git", from: "0.9.9-µ5")
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
.target(name: "GzipMiddleware", dependencies: ["Vapor", "ZIPFoundation"]),
|
.target(name: "GzipMiddleware", dependencies: ["Vapor", "ZIPFoundation"]),
|
||||||
|
|
|
@ -51,14 +51,17 @@ public struct GzipServerMiddleware: Middleware, ServiceType {
|
||||||
return stream.write(.chunk(buffer))
|
return stream.write(.chunk(buffer))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
_ = write.flatMap {
|
write = write.flatMap {
|
||||||
buffer.clear()
|
buffer.clear()
|
||||||
buffer.write(integer: crc32, endianness: .little)
|
buffer.write(integer: crc32, endianness: .little)
|
||||||
buffer.write(integer: UInt32(data.count), endianness: .little)
|
buffer.write(integer: UInt32(data.count), endianness: .little)
|
||||||
return stream.write(.chunk(buffer))
|
return stream.write(.chunk(buffer))
|
||||||
}.flatMap {
|
}.flatMap {
|
||||||
return stream.write(.end)
|
return stream.write(.end)
|
||||||
}.transform(to: ())
|
}
|
||||||
|
DispatchQueue.global().async {
|
||||||
|
_ = try? write.wait()
|
||||||
|
}
|
||||||
|
|
||||||
let httpResponse = HTTPResponse(status: response.http.status, headers: headers, body: stream)
|
let httpResponse = HTTPResponse(status: response.http.status, headers: headers, body: stream)
|
||||||
return request.response(http: httpResponse)
|
return request.response(http: httpResponse)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user