Skip to content

Commit

Permalink
Changes from PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed May 11, 2024
1 parent 5a32fb0 commit b5c5766
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ struct DecompressByteBufferSequence<Base: AsyncSequence & Sendable>: AsyncSequen
if self.currentBuffer == nil {
self.currentBuffer = try await self.baseIterator.next()
}
self.window.moveReaderIndex(to: 0)
self.window.moveWriterIndex(to: 0)
self.window.clear()
while var buffer = self.currentBuffer {
do {
try buffer.decompressStream(to: &self.window, with: self.decompressor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,17 @@ public struct ResponseCompressionMiddleware<Context: BaseRequestContext>: Router
/// Finish compressed response writing
func finish() async throws {
// The last buffer must be finished
if var lastBuffer {
var window = self.compressor.window!
if var lastBuffer, var window = self.compressor.window {
// keep finishing stream until we don't get a buffer overflow
while true {
do {
try lastBuffer.compressStream(to: &window, with: self.compressor, flush: .finish)
try await self.parentWriter.write(window)
window.moveReaderIndex(to: 0)
window.moveWriterIndex(to: 0)
window.clear()
break
} catch let error as CompressNIOError where error == .bufferOverflow {
try await self.parentWriter.write(window)
window.moveReaderIndex(to: 0)
window.moveWriterIndex(to: 0)
window.clear()
}
}
}
Expand Down

0 comments on commit b5c5766

Please sign in to comment.