func requestFullyProcessed()

in backpressure-file-io-channel/Sources/BackpressureChannelToFileIO/SaveEverythingHTTPServer.swift [96:120]


    func requestFullyProcessed(context: ChannelHandlerContext, result: Result<Void, Error>) {
        switch result {
        case .success:
            context.write(self.wrapOutboundOut(HTTPServerResponsePart.head(.init(version: .init(major: 1,
                                                                                                minor: 1),
                                                                                 status: .ok,
                                                                                 headers: ["content-length": "0"]))),
                          promise: nil)
            context.writeAndFlush(self.wrapOutboundOut(HTTPServerResponsePart.end(nil)), promise: nil)
        case .failure(let error):
            let errorPage = "ERROR on \(context.channel): \(error)"
            context.write(self.wrapOutboundOut(HTTPServerResponsePart.head(.init(version: .init(major: 1,
                                                                                                minor: 1),
                                                                                 status: .internalServerError,
                                                                                 headers: ["connection": "close",
                                                                                           "content-length": "\(errorPage.utf8.count)"]))),
                          promise: nil)
            var buffer = context.channel.allocator.buffer(capacity: errorPage.utf8.count)
            buffer.writeString(errorPage)
            context.write(self.wrapOutboundOut(HTTPServerResponsePart.body(.byteBuffer(buffer))), promise: nil)
            context.writeAndFlush(self.wrapOutboundOut(HTTPServerResponsePart.end(nil))).whenComplete { _ in
                context.close(promise: nil)
            }
        }
    }