Fix `HTTPResumableUploadHandler` silently dropping all responses after the first request on a connection. ### Motivation: `HTTPResumableUploadHandler` forwards all outbound operations through its stored `ChannelHandlerContext`, which is set only in `handlerAdded` and cleared by `detach()` whenever an upload releases the handler. When a second request arrives on the same channel — the normal case for HTTP/1.1 with keep-alive — `channelRead` calls `resetUpload`, which ends the previous upload. That synchronously detaches the handler and clears its context, and nothing restores it before the new upload is attached. Every response write for the second and subsequent requests then hits `self.context?.write(...)` as a no-op: the response is silently dropped, write promises never complete, and `read()` forwarding to the parent channel stops, so the client hangs until it times out. The existing tests never caught this because each test sends one request per `EmbeddedChannel`; resumption is only exercised across separate channels, and per-stream channels (HTTP/2) recreate the handler per request, which also masks the bug. ### Modifications: - Restore `self.context` in `resetUpload(context:)` after ending the previous upload. - Add `testNonUploadKeepAlive` and `testResumableUploadKeepAlive`, which send a second request on the same `EmbeddedChannel` for pass-through traffic and after a completed upload creation respectively. Both fail without the fix. ### Result: Connections handled by `HTTPResumableUploadHandler` can serve more than one request: responses to the second and subsequent requests on a keep-alive connection are delivered instead of being silently dropped. Fixes #318 Co-authored-by: Cory Benfield <lukasa@apple.com>
NIOExtras
NIOExtras is a good place for code that is related to NIO but not core. It can also be used to incubate APIs for tasks that are possible with core-NIO but are cumbersome today.
What makes a good contribution to NIOExtras?
- a protocol encoder/decoder pair (also called "codec") that is often used but is small enough so it doesn't need its own repository
- a helper to achieve a task that is harder-than-necessary to achieve with core-NIO
Code Quality / Stability
All code will go through code review like in the other repositories related to the SwiftNIO project.
swift-nio-extras part of the SwiftNIO 2 family of repositories and depends on the following:
swift-nio, version 2.30.0 or better.- Swift 5.7.1
zliband its development headers installed on the system. But don't worry, you'll findzlibon pretty much any UNIX system that can compile any sort of code.
To depend on swift-nio-extras, put the following in the dependencies of your Package.swift:
.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.0.0"),
Support for older Swift versions
The most recent versions of SwiftNIO Extras support Swift 5.7.1 and newer. The minimum Swift version supported by SwiftNIO Extras releases are detailed below:
| SwiftNIO Extras | Minimum Swift Version |
|---|---|
1.0.0 ..< 1.10.0 |
5.0 |
1.10.0 ..< 1.11.0 |
5.2 |
1.11.0 ..< 1.14.0 |
5.4 |
1.14.0 ..< 1.19.0 |
5.5.2 |
1.19.0 ..< 1.20.0 |
5.6 |
1.20.0 ..< 1.23.0 |
5.7.1 |
1.23.0 ..< 1.27.0 |
5.8 |
1.27.0 ..< 1.30.0 |
5.10 |
1.30.0 ..< 1.34.0 |
6.0 |
1.34.0 ..< |
6.1 |
On the nio-extras-0.1 branch, you can find the swift-nio-extras version for the SwiftNIO 1 family. It requires Swift 4.1 or better.
Current Contents
QuiescingHelper: Helps to quiesce a server by notifying user code when all previously open connections have closed.LineBasedFrameDecoderSplits incomingByteBuffers on line endings.FixedLengthFrameDecoderSplits incomingByteBuffers by a fixed number of bytes.LengthFieldBasedFrameDecoderSplits incomingByteBuffers by a number of bytes specified in a fixed length header contained within the buffer.LengthFieldPrependerPrepends the number of bytes to outgoingByteBuffers as a fixed length header. Can be used in a codec pair with theLengthFieldBasedFrameDecoder.RequestResponseHandlerMatches a request and a promise with the corresponding response.HTTPResponseCompressorCompresses the body of every HTTP/1 response message.DebugInboundsEventHandlerPrints out all inbound events that travel through theChannelPipeline.DebugOutboundsEventHandlerPrints out all outbound events that travel through theChannelPipeline.WritePCAPHandlerAChannelHandlerthat writes.pcapcontaining the traffic of theChannelPipelinethat you can inspect with Wireshark/tcpdump.HTTP1ToHTTPClientCodecAChannelHandlerthat translates HTTP/1 messages into shared HTTP types for the client side.HTTP1ToHTTPServerCodecAChannelHandlerthat translates HTTP/1 messages into shared HTTP types for the server side.HTTPToHTTP1ClientCodecAChannelHandlerthat translates shared HTTP types into HTTP/1 messages for the client side for compatibility purposes.HTTPToHTTP1ServerCodecAChannelHandlerthat translates shared HTTP types into HTTP/1 messages for the server side for compatibility purposes.HTTP2FramePayloadToHTTPClientCodecAChannelHandlerthat translates HTTP/2 concepts into shared HTTP types for the client side.HTTP2FramePayloadToHTTPServerCodecAChannelHandlerthat translates HTTP/2 concepts into shared HTTP types for the server side.HTTPResumableUploadHandlerAChannelHandlerthat translates HTTP resumable uploads to regular uploads.HTTPDrippingDownloadHandlerAChannelHandlerthat sends a configurable stream of zeroes to a client.HTTPReceiveDiscardHandlerAChannelHandlerthat receives arbitrary bytes from a client and discards them.