Skip to content

Commit

Permalink
Upgrade swift-nio to 1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
glbrntt authored and MrMage committed Jan 6, 2019
1 parent 78c5fed commit a43337c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
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

0 comments on commit a43337c

Please sign in to comment.