的目的是什么HTTP2ToHTTP1ServerCodec
。为什么需要将 HTTP/2 转换为 HTTP/1 协议?
channel.configureHTTP2Pipeline(mode: .server) { (streamChannel, streamID) -> EventLoopFuture<Void> in
// For every HTTP/2 stream that the client opens, we put in the `HTTP2ToHTTP1ServerCodec` which
// transforms the HTTP/2 frames to the HTTP/1 messages from the `NIOHTTP1` module.
streamChannel.pipeline.addHandler(HTTP2ToHTTP1ServerCodec(streamID: streamID)).flatMap { () -> EventLoopFuture<Void> in
// And lastly, we put in our very basic HTTP server :).
streamChannel.pipeline.addHandler(HTTPServer())
这是来自 Swift NIO 示例 repo的修改代码片段。