Skip to content

Don't send the empty trailers when we've sent a 200 OK to a CONNECT request #3260

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

Open
Lukasa opened this issue May 30, 2025 · 0 comments
Open

Comments

@Lukasa
Copy link
Contributor

Lukasa commented May 30, 2025

As shown in apple/swift-nio-ssl#539, when responding to a CONNECT request, if you send a .end then we will happily send a chunk-encoded empty blob. That is, the code below:

    func channelRead(context: ChannelHandlerContext, data: NIOAny) {
        let part = unwrapInboundIn(data)
        guard case let .head(request) = part, request.method == .CONNECT else {
            context.fireChannelRead(data)
            return
        }

        connectHost = request.uri.components(separatedBy: ":").first

        var responseHead = HTTPResponseHead(version: request.version, status: .ok)
        responseHead.headers.add(name: "Connection", value: "Established")
        context.write(self.wrapOutboundOut(.head(responseHead)), promise: nil)
        context.writeAndFlush(self.wrapOutboundOut(.end(nil))).whenComplete { _ in
            self.upgradeToTLS(context: context)
        }
    }

is incorrect. The .end should not be sent.

We can do better than this, and refuse to send anything in this context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant