Skip to content

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

@Lukasa

Description

@Lukasa

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions