Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var packageDependencies: [Package.Dependency] = [
.package(url: "https://github.com/apple/swift-protobuf.git", .upToNextMinor(from: "1.1.1")),
.package(url: "https://github.com/kylef/Commander.git", .upToNextMinor(from: "0.8.0")),
.package(url: "https://github.com/apple/swift-nio-zlib-support.git", .upToNextMinor(from: "1.0.0")),
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMinor(from: "1.11.0")),
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMinor(from: "1.12.0")),
.package(url: "https://github.com/apple/swift-nio-nghttp2-support.git", .upToNextMinor(from: "1.0.0")),
.package(url: "https://github.com/apple/swift-nio-http2.git", .revision("dd9339e6310ad8537a271f3ff60a4f3976ca8e4d"))
]
Expand Down
19 changes: 12 additions & 7 deletions Sources/SwiftGRPCNIO/GRPCChannelHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,20 @@ extension GRPCChannelHandler: ChannelInboundHandler {
return
}

var responseHeaders = HTTPHeaders()
responseHeaders.add(name: "content-type", value: "application/grpc")
ctx.write(self.wrapOutboundOut(.headers(responseHeaders)), promise: nil)

let codec = callHandler.makeGRPCServerCodec()
let handlerRemoved: EventLoopPromise<Bool> = ctx.eventLoop.newPromise()
handlerRemoved.futureResult.whenSuccess { handlerWasRemoved in
assert(handlerWasRemoved)

ctx.pipeline.add(handler: callHandler, after: codec).whenComplete {
var responseHeaders = HTTPHeaders()
responseHeaders.add(name: "content-type", value: "application/grpc")
ctx.write(self.wrapOutboundOut(.headers(responseHeaders)), promise: nil)
}
}

ctx.pipeline.add(handler: codec, after: self)
.then { ctx.pipeline.add(handler: callHandler, after: codec) }
//! FIXME(lukasa): Fix the ordering of this with NIO 1.12 and replace with `remove(, promise:)`.
.whenComplete { _ = ctx.pipeline.remove(handler: self) }
.whenComplete { ctx.pipeline.remove(handler: self, promise: handlerRemoved) }

case .message, .end:
preconditionFailure("received \(requestPart), should have been removed as a handler at this point")
Expand Down