in Sources/NIOHTTPCompression/HTTPResponseCompressor.swift [281:299]
mutating func flush(compressor: inout NIOCompression.Compressor, allocator: ByteBufferAllocator) -> (HTTPResponseHead?, ByteBuffer?, HTTPServerResponsePart?) {
var outputBody: ByteBuffer? = nil
if self.body.readableBytes > 0 || mustFlush {
let compressedBody = compressor.compress(inputBuffer: &self.body, allocator: allocator, finalise: mustFlush)
if isCompleteResponse {
head!.headers.remove(name: "transfer-encoding")
head!.headers.replaceOrAdd(name: "content-length", value: "\(compressedBody.readableBytes)")
}
else if head != nil && head!.status.mayHaveResponseBody {
head!.headers.remove(name: "content-length")
head!.headers.replaceOrAdd(name: "transfer-encoding", value: "chunked")
}
outputBody = compressedBody
}
let response = (head, outputBody, end)
clear()
return response
}