Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for non mutating response body writer #28

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let package = Package(
.library(name: "HummingbirdCompression", targets: ["HummingbirdCompression"])
],
dependencies: [
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0"),
.package(url: "https://github.com/hummingbird-project/hummingbird.git", branch: "non-mutating-response-body-writer"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mark: Branch

.package(url: "https://github.com/adam-fowler/compress-nio.git", from: "1.4.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.32.1"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Logging

// ResponseBodyWriter that writes a compressed version of the response to a parent writer
final class CompressedBodyWriter<ParentWriter: ResponseBodyWriter & Sendable>: ResponseBodyWriter {
var parentWriter: ParentWriter
let parentWriter: ParentWriter
private let compressor: ZlibCompressor
private var window: ByteBuffer
var lastBuffer: ByteBuffer?
Expand Down
11 changes: 8 additions & 3 deletions Tests/HummingbirdCompressionTests/CompressionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,16 @@ class HummingBirdCompressionTests: XCTestCase {
struct VerifyResponseBodyChunkSize<Context: RequestContext>: RouterMiddleware {
let bufferSize: Int

struct Writer: ResponseBodyWriter {
var parentWriter: any ResponseBodyWriter
final class Writer: ResponseBodyWriter {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a strong preference here? Since the type is internal I don't think we necessarily want to change this

let parentWriter: any ResponseBodyWriter
let bufferSize: Int

mutating func write(_ buffer: ByteBuffer) async throws {
init(parentWriter: any ResponseBodyWriter, bufferSize: Int) {
self.parentWriter = parentWriter
self.bufferSize = bufferSize
}

func write(_ buffer: ByteBuffer) async throws {
XCTAssertLessThanOrEqual(buffer.capacity, self.bufferSize)
try await self.parentWriter.write(buffer)
}
Expand Down
Loading