mirror of
https://github.com/apple/swift-nio
synced 2026-11-25 04:47:49 +00:00
ChannelPipeline: addHandler and removeHandler instead of add/remove (#817)
Motivation: - `ChannelPipeline.add(name:handler:...)` had a strange order of arguments - `remove(handler:)` and `remove(ctx:)` both remove `ChannelHandler`s but they read like they remove different things So let's just fix the argument order and name them `addHandler` and `removeHandler` making clear what they do. Modifications: - rename all `ChannelPipeline.add(name:handler:...)`s to `ChannelPipeline.addHandler(_:name:...)` - rename all `ChannelPipeline.remove(...)`s to `ChannelPipeline.removeHandler(...)` Result: more readable and consistent code
This commit is contained in:
1 parent
5d27e59bd9
commit
46ffd630de
50 files changed
+539
-425
No files matched your search
+4
-4
@@ -221,7 +221,7 @@ public func swiftMain() -> Int {
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.configureHTTPServerPipeline(withPipeliningAssistance: true,
|
||||
withErrorHandling: false).flatMap {
|
||||
channel.pipeline.add(handler: SimpleHTTPServer())
|
||||
channel.pipeline.addHandler(SimpleHTTPServer())
|
||||
}
|
||||
}.bind(host: "127.0.0.1", port: 0).wait()
|
||||
|
||||
@@ -235,7 +235,7 @@ public func swiftMain() -> Int {
|
||||
let clientChannel = try ClientBootstrap(group: group)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.addHTTPClientHandlers().flatMap {
|
||||
channel.pipeline.add(handler: repeatedRequestsHandler)
|
||||
channel.pipeline.addHandler(repeatedRequestsHandler)
|
||||
}
|
||||
}
|
||||
.channelOption(ChannelOptions.socket(IPPROTO_TCP, TCP_NODELAY), value: 1)
|
||||
@@ -253,7 +253,7 @@ public func swiftMain() -> Int {
|
||||
.childChannelOption(ChannelOptions.socket(IPPROTO_TCP, TCP_NODELAY), value: 1)
|
||||
.childChannelOption(ChannelOptions.recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: 4))
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: PongHandler())
|
||||
channel.pipeline.addHandler(PongHandler())
|
||||
}.bind(host: "127.0.0.1", port: 0).wait()
|
||||
|
||||
defer {
|
||||
@@ -263,7 +263,7 @@ public func swiftMain() -> Int {
|
||||
let pingHandler = PingHandler(numberOfRequests: numberOfRequests, eventLoop: group.next())
|
||||
_ = try ClientBootstrap(group: group)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.add(handler: pingHandler)
|
||||
channel.pipeline.addHandler(pingHandler)
|
||||
}
|
||||
.channelOption(ChannelOptions.socket(IPPROTO_TCP, TCP_NODELAY), value: 1)
|
||||
.channelOption(ChannelOptions.recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: 4))
|
||||
|
||||
@@ -29,10 +29,10 @@
|
||||
/// // Set the handlers that are applied to the accepted child `Channel`s.
|
||||
/// .childChannelInitializer { channel in
|
||||
/// // Ensure we don't read faster then we can write by adding the BackPressureHandler into the pipeline.
|
||||
/// channel.pipeline.add(handler: BackPressureHandler()).flatMap { () in
|
||||
/// channel.pipeline.addHandler(BackPressureHandler()).flatMap { () in
|
||||
/// // make sure to instantiate your `ChannelHandlers` inside of
|
||||
/// // the closure as it will be invoked once per connection.
|
||||
/// channel.pipeline.add(handler: MyChannelHandler())
|
||||
/// channel.pipeline.addHandler(MyChannelHandler())
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
@@ -219,7 +219,7 @@ public final class ServerBootstrap {
|
||||
|
||||
return eventLoop.submit {
|
||||
return serverChannelInit(serverChannel).flatMap {
|
||||
serverChannel.pipeline.add(handler: AcceptHandler(childChannelInitializer: childChannelInit,
|
||||
serverChannel.pipeline.addHandler(AcceptHandler(childChannelInitializer: childChannelInit,
|
||||
childChannelOptions: childChannelOptions))
|
||||
}.flatMap {
|
||||
serverChannelOptions.applyAll(channel: serverChannel)
|
||||
@@ -339,7 +339,7 @@ private extension Channel {
|
||||
/// // always instantiate the handler _within_ the closure as
|
||||
/// // it may be called multiple times (for example if the hostname
|
||||
/// // resolves to both IPv4 and IPv6 addresses, cf. Happy Eyeballs).
|
||||
/// channel.pipeline.add(handler: MyChannelHandler())
|
||||
/// channel.pipeline.addHandler(MyChannelHandler())
|
||||
/// }
|
||||
/// try! bootstrap.connect(host: "example.org", port: 12345).wait()
|
||||
/// /* the Channel is now connected */
|
||||
@@ -549,7 +549,7 @@ public final class ClientBootstrap {
|
||||
/// // Enable SO_REUSEADDR.
|
||||
/// .channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
/// .channelInitializer { channel in
|
||||
/// channel.pipeline.add(handler: MyChannelHandler())
|
||||
/// channel.pipeline.addHandler(MyChannelHandler())
|
||||
/// }
|
||||
/// let channel = try! bootstrap.bind(host: "127.0.0.1", port: 53).wait()
|
||||
/// /* the Channel is now ready to send/receive datagrams */
|
||||
|
||||
@@ -160,9 +160,11 @@ public final class ChannelPipeline: ChannelInvoker {
|
||||
/// - parameters:
|
||||
/// - name: the name to use for the `ChannelHandler` when its added. If none is specified it will generate a name.
|
||||
/// - handler: the `ChannelHandler` to add
|
||||
/// - first: `true` to add this handler to the front of the `ChannelPipeline`, `false to add it last
|
||||
/// - position: The position in the `ChannelPipeline` to add `handler`. Defaults to `.last`.
|
||||
/// - returns: the `EventLoopFuture` which will be notified once the `ChannelHandler` was added.
|
||||
public func add(name: String? = nil, handler: ChannelHandler, first: Bool = false) -> EventLoopFuture<Void> {
|
||||
public func addHandler(_ handler: ChannelHandler,
|
||||
name: String? = nil,
|
||||
position: ChannelPipeline.Position = .last) -> EventLoopFuture<Void> {
|
||||
let promise = self.eventLoop.makePromise(of: Void.self)
|
||||
|
||||
func _add() {
|
||||
@@ -171,10 +173,31 @@ public final class ChannelPipeline: ChannelInvoker {
|
||||
return
|
||||
}
|
||||
|
||||
if first {
|
||||
self.add0(name: name, handler: handler, relativeContext: head!, operation: self.add0(context:after:), promise: promise)
|
||||
} else {
|
||||
self.add0(name: name, handler: handler, relativeContext: tail!, operation: self.add0(context:before:), promise: promise)
|
||||
switch position {
|
||||
case .first:
|
||||
self.add0(name: name,
|
||||
handler: handler,
|
||||
relativeContext: head!,
|
||||
operation: self.add0(context:after:),
|
||||
promise: promise)
|
||||
case .last:
|
||||
self.add0(name: name,
|
||||
handler: handler,
|
||||
relativeContext: tail!,
|
||||
operation: self.add0(context:before:),
|
||||
promise: promise)
|
||||
case .before(let beforeHandler):
|
||||
self.add0(name: name,
|
||||
handler: handler,
|
||||
relativeHandler: beforeHandler,
|
||||
operation: self.add0(context:before:),
|
||||
promise: promise)
|
||||
case .after(let afterHandler):
|
||||
self.add0(name: name,
|
||||
handler: handler,
|
||||
relativeHandler: afterHandler,
|
||||
operation: self.add0(context:after:),
|
||||
promise: promise)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,52 +212,6 @@ public final class ChannelPipeline: ChannelInvoker {
|
||||
return promise.futureResult
|
||||
}
|
||||
|
||||
/// Add a `ChannelHandler` to the `ChannelPipeline` immediately after a `ChannelHandler` that is already present
|
||||
/// in the `ChannelPipeline`.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - name: The name to use for the `ChannelHandler` when its added. If none is specified, a name will be
|
||||
/// automatically generated.
|
||||
/// - handler: The `ChannelHandler` to add.
|
||||
/// - after: The pre-existing `ChannelHandler` that `handler` should be inserted immediately after.
|
||||
/// - returns: An `EventLoopFuture` that will be notified when the `ChannelHandler` is added.
|
||||
public func add(name: String? = nil, handler: ChannelHandler, after: ChannelHandler) -> EventLoopFuture<Void> {
|
||||
let promise = self.eventLoop.makePromise(of: Void.self)
|
||||
|
||||
if self.eventLoop.inEventLoop {
|
||||
self.add0(name: name, handler: handler, relativeHandler: after, operation: self.add0(context:after:), promise: promise)
|
||||
} else {
|
||||
self.eventLoop.execute {
|
||||
self.add0(name: name, handler: handler, relativeHandler: after, operation: self.add0(context:after:), promise: promise)
|
||||
}
|
||||
}
|
||||
|
||||
return promise.futureResult
|
||||
}
|
||||
|
||||
/// Add a `ChannelHandler` to the `ChannelPipeline` immediately before a `ChannelHandler` that is already present
|
||||
/// in the `ChannelPipeline`.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - name: The name to use for the `ChannelHandler` when its added. If none is specified, a name will be
|
||||
/// automatically generated.
|
||||
/// - handler: The `ChannelHandler` to add.
|
||||
/// - after: The pre-existing `ChannelHandler` that `handler` should be inserted immediately before.
|
||||
/// - returns: An `EventLoopFuture` that will be notified when the `ChannelHandler` is added.
|
||||
public func add(name: String? = nil, handler: ChannelHandler, before: ChannelHandler) -> EventLoopFuture<Void> {
|
||||
let promise = self.eventLoop.makePromise(of: Void.self)
|
||||
|
||||
if self.eventLoop.inEventLoop {
|
||||
self.add0(name: name, handler: handler, relativeHandler: before, operation: self.add0(context:before:), promise: promise)
|
||||
} else {
|
||||
self.eventLoop.execute {
|
||||
self.add0(name: name, handler: handler, relativeHandler: before, operation: self.add0(context:before:), promise: promise)
|
||||
}
|
||||
}
|
||||
|
||||
return promise.futureResult
|
||||
}
|
||||
|
||||
/// Synchronously add a `ChannelHandler` to the pipeline, relative to another `ChannelHandler`,
|
||||
/// where the insertion is done by a specific operation.
|
||||
///
|
||||
@@ -355,9 +332,9 @@ public final class ChannelPipeline: ChannelInvoker {
|
||||
/// - parameters:
|
||||
/// - handler: the `ChannelHandler` to remove.
|
||||
/// - returns: the `EventLoopFuture` which will be notified once the `ChannelHandler` was removed.
|
||||
public func remove(handler: RemovableChannelHandler) -> EventLoopFuture<Void> {
|
||||
public func removeHandler(_ handler: RemovableChannelHandler) -> EventLoopFuture<Void> {
|
||||
let promise = self.eventLoop.makePromise(of: Void.self)
|
||||
self.remove(handler: handler, promise: promise)
|
||||
self.removeHandler(handler, promise: promise)
|
||||
return promise.futureResult
|
||||
}
|
||||
|
||||
@@ -366,9 +343,9 @@ public final class ChannelPipeline: ChannelInvoker {
|
||||
/// - parameters:
|
||||
/// - name: the name that was used to add the `ChannelHandler` to the `ChannelPipeline` before.
|
||||
/// - returns: the `EventLoopFuture` which will be notified once the `ChannelHandler` was removed.
|
||||
public func remove(name: String) -> EventLoopFuture<Void> {
|
||||
public func removeHandler(name: String) -> EventLoopFuture<Void> {
|
||||
let promise = self.eventLoop.makePromise(of: Void.self)
|
||||
self.remove(name: name, promise: promise)
|
||||
self.removeHandler(name: name, promise: promise)
|
||||
return promise.futureResult
|
||||
}
|
||||
|
||||
@@ -377,9 +354,9 @@ public final class ChannelPipeline: ChannelInvoker {
|
||||
/// - parameters:
|
||||
/// - ctx: the `ChannelHandlerContext` that belongs to `ChannelHandler` that should be removed.
|
||||
/// - returns: the `EventLoopFuture` which will be notified once the `ChannelHandler` was removed.
|
||||
public func remove(ctx: ChannelHandlerContext) -> EventLoopFuture<Void> {
|
||||
public func removeHandler(ctx: ChannelHandlerContext) -> EventLoopFuture<Void> {
|
||||
let promise = self.eventLoop.makePromise(of: Void.self)
|
||||
self.remove(ctx: ctx, promise: promise)
|
||||
self.removeHandler(ctx: ctx, promise: promise)
|
||||
return promise.futureResult
|
||||
}
|
||||
|
||||
@@ -388,11 +365,11 @@ public final class ChannelPipeline: ChannelInvoker {
|
||||
/// - parameters:
|
||||
/// - handler: the `ChannelHandler` to remove.
|
||||
/// - promise: An `EventLoopPromise` that will complete when the `ChannelHandler` is removed.
|
||||
public func remove(handler: RemovableChannelHandler, promise: EventLoopPromise<Void>?) {
|
||||
public func removeHandler(_ handler: RemovableChannelHandler, promise: EventLoopPromise<Void>?) {
|
||||
let contextFuture = self.context0 {
|
||||
return $0.handler === handler
|
||||
}.map { ctx in
|
||||
self.remove(ctx: ctx, promise: promise)
|
||||
self.removeHandler(ctx: ctx, promise: promise)
|
||||
}
|
||||
|
||||
contextFuture.cascadeFailure(to: promise)
|
||||
@@ -403,11 +380,11 @@ public final class ChannelPipeline: ChannelInvoker {
|
||||
/// - parameters:
|
||||
/// - name: the name that was used to add the `ChannelHandler` to the `ChannelPipeline` before.
|
||||
/// - promise: An `EventLoopPromise` that will complete when the `ChannelHandler` is removed.
|
||||
public func remove(name: String, promise: EventLoopPromise<Void>?) {
|
||||
public func removeHandler(name: String, promise: EventLoopPromise<Void>?) {
|
||||
let contextFuture = self.context0 {
|
||||
$0.name == name
|
||||
}.map { ctx in
|
||||
self.remove(ctx: ctx, promise: promise)
|
||||
self.removeHandler(ctx: ctx, promise: promise)
|
||||
}
|
||||
|
||||
contextFuture.cascadeFailure(to: promise)
|
||||
@@ -418,7 +395,7 @@ public final class ChannelPipeline: ChannelInvoker {
|
||||
/// - parameters:
|
||||
/// - ctx: the `ChannelHandlerContext` that belongs to `ChannelHandler` that should be removed.
|
||||
/// - promise: An `EventLoopPromise` that will complete when the `ChannelHandler` is removed.
|
||||
public func remove(ctx: ChannelHandlerContext, promise: EventLoopPromise<Void>?) {
|
||||
public func removeHandler(ctx: ChannelHandlerContext, promise: EventLoopPromise<Void>?) {
|
||||
guard let handler = ctx.handler as? RemovableChannelHandler else {
|
||||
promise?.fail(ChannelError.unremovableHandler)
|
||||
return
|
||||
@@ -900,16 +877,27 @@ extension ChannelPipeline {
|
||||
///
|
||||
/// - parameters:
|
||||
/// - handlers: The array of `ChannelHandler`s to be added.
|
||||
/// - first: If `true`, the supplied `ChannelHandler`s will be added to the front of the pipeline.
|
||||
/// If `false`, they will be added to the back.
|
||||
/// - position: The position in the `ChannelPipeline` to add `handlers`. Defaults to `.last`.
|
||||
///
|
||||
/// - returns: A future that will be completed when all of the supplied `ChannelHandler`s were added.
|
||||
public func addHandlers(_ handlers: [ChannelHandler], first: Bool) -> EventLoopFuture<Void> {
|
||||
public func addHandlers(_ handlers: [ChannelHandler],
|
||||
position: ChannelPipeline.Position = .last) -> EventLoopFuture<Void> {
|
||||
var handlers = handlers
|
||||
if first {
|
||||
handlers = handlers.reversed()
|
||||
let individualPosition: ChannelPipeline.Position
|
||||
switch position {
|
||||
case .first:
|
||||
handlers.reverse()
|
||||
individualPosition = .first
|
||||
case .last:
|
||||
individualPosition = .last
|
||||
case .before(let handler):
|
||||
individualPosition = .before(handler)
|
||||
case .after(let handler):
|
||||
handlers.reverse()
|
||||
individualPosition = .after(handler)
|
||||
|
||||
}
|
||||
return .andAllSucceed(handlers.map { add(handler: $0, first: first) }, on: eventLoop)
|
||||
return .andAllSucceed(handlers.map { addHandler($0, position: individualPosition) }, on: eventLoop)
|
||||
}
|
||||
|
||||
/// Adds the provided channel handlers to the pipeline in the order given, taking account
|
||||
@@ -917,12 +905,29 @@ extension ChannelPipeline {
|
||||
///
|
||||
/// - parameters:
|
||||
/// - handlers: One or more `ChannelHandler`s to be added.
|
||||
/// - first: If `true`, the supplied `ChannelHandler`s will be added to the front of the pipeline.
|
||||
/// If `false`, they will be added to the back.
|
||||
/// - position: The position in the `ChannelPipeline` to add `handlers`. Defaults to `.last`.
|
||||
///
|
||||
/// - returns: A future that will be completed when all of the supplied `ChannelHandler`s were added.
|
||||
public func addHandlers(_ handlers: ChannelHandler..., first: Bool) -> EventLoopFuture<Void> {
|
||||
return addHandlers(handlers, first: first)
|
||||
public func addHandlers(_ handlers: ChannelHandler...,
|
||||
position: ChannelPipeline.Position = .last) -> EventLoopFuture<Void> {
|
||||
return addHandlers(handlers, position: position)
|
||||
}
|
||||
}
|
||||
|
||||
extension ChannelPipeline {
|
||||
/// A `Position` within the `ChannelPipeline` used to insert handlers into the `ChannelPipeline`.
|
||||
public enum Position {
|
||||
/// The first `ChannelHandler` -- the front of the `ChannelPipeline`.
|
||||
case first
|
||||
|
||||
/// The last `ChannelHandler` -- the back of the `ChannelPipeline`.
|
||||
case last
|
||||
|
||||
/// Before the given `ChannelHandler`.
|
||||
case before(ChannelHandler)
|
||||
|
||||
/// After the given `ChannelHandler`.
|
||||
case after(ChannelHandler)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -378,7 +378,7 @@ public class EmbeddedChannel: Channel {
|
||||
|
||||
if let handler = handler {
|
||||
// This will be propagated via fireErrorCaught
|
||||
_ = try? _pipeline.add(handler: handler).wait()
|
||||
_ = try? _pipeline.addHandler(handler).wait()
|
||||
}
|
||||
|
||||
// This will never throw...
|
||||
|
||||
@@ -46,7 +46,7 @@ let bootstrap = ClientBootstrap(group: group)
|
||||
// Enable SO_REUSEADDR.
|
||||
.channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.add(handler: ChatHandler())
|
||||
channel.pipeline.addHandler(ChatHandler())
|
||||
}
|
||||
defer {
|
||||
try! group.syncShutdownGracefully()
|
||||
|
||||
@@ -122,9 +122,9 @@ let bootstrap = ServerBootstrap(group: group)
|
||||
// Set the handlers that are applied to the accepted Channels
|
||||
.childChannelInitializer { channel in
|
||||
// Add handler that will buffer data until a \n is received
|
||||
channel.pipeline.add(handler: ByteToMessageHandler(LineDelimiterCodec())).flatMap { v in
|
||||
channel.pipeline.addHandler(ByteToMessageHandler(LineDelimiterCodec())).flatMap { v in
|
||||
// It's important we use the same handler for all accepted channels. The ChatHandler is thread-safe!
|
||||
channel.pipeline.add(handler: chatHandler)
|
||||
channel.pipeline.addHandler(chatHandler)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ let bootstrap = ClientBootstrap(group: group)
|
||||
// Enable SO_REUSEADDR.
|
||||
.channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.add(handler: EchoHandler())
|
||||
channel.pipeline.addHandler(EchoHandler())
|
||||
}
|
||||
defer {
|
||||
try! group.syncShutdownGracefully()
|
||||
|
||||
@@ -45,8 +45,8 @@ let bootstrap = ServerBootstrap(group: group)
|
||||
// Set the handlers that are appled to the accepted Channels
|
||||
.childChannelInitializer { channel in
|
||||
// Ensure we don't read faster than we can write by adding the BackPressureHandler into the pipeline.
|
||||
channel.pipeline.add(handler: BackPressureHandler()).flatMap { v in
|
||||
channel.pipeline.add(handler: EchoHandler())
|
||||
channel.pipeline.addHandler(BackPressureHandler()).flatMap { v in
|
||||
channel.pipeline.addHandler(EchoHandler())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,12 +24,12 @@ extension ChannelPipeline {
|
||||
/// Configure a `ChannelPipeline` for use as a HTTP client.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - first: Whether to add the HTTP client at the head of the channel pipeline,
|
||||
/// or at the tail.
|
||||
/// - position: The position in the `ChannelPipeline` where to add the HTTP client handlers. Defaults to `.last`.
|
||||
/// - returns: An `EventLoopFuture` that will fire when the pipeline is configured.
|
||||
public func addHTTPClientHandlers(first: Bool = false,
|
||||
public func addHTTPClientHandlers(position: ChannelPipeline.Position = .last,
|
||||
leftOverBytesStrategy: RemoveAfterUpgradeStrategy = .dropBytes) -> EventLoopFuture<Void> {
|
||||
return addHandlers(HTTPRequestEncoder(), HTTPResponseDecoder(leftOverBytesStrategy: leftOverBytesStrategy), first: first)
|
||||
return addHandlers(HTTPRequestEncoder(), HTTPResponseDecoder(leftOverBytesStrategy: leftOverBytesStrategy),
|
||||
position: position)
|
||||
}
|
||||
|
||||
/// Configure a `ChannelPipeline` for use as a HTTP server.
|
||||
@@ -45,8 +45,7 @@ extension ChannelPipeline {
|
||||
/// features.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - first: Whether to add the HTTP server at the head of the channel pipeline,
|
||||
/// or at the tail.
|
||||
/// - position: Where in the pipeline to add the HTTP server handlers, defaults to `.last`.
|
||||
/// - pipelining: Whether to provide assistance handling HTTP clients that pipeline
|
||||
/// their requests. Defaults to `true`. If `false`, users will need to handle
|
||||
/// clients that pipeline themselves.
|
||||
@@ -58,7 +57,7 @@ extension ChannelPipeline {
|
||||
/// - errorHandling: Whether to provide assistance handling protocol errors (e.g.
|
||||
/// failure to parse the HTTP request) by sending 400 errors. Defaults to `true`.
|
||||
/// - returns: An `EventLoopFuture` that will fire when the pipeline is configured.
|
||||
public func configureHTTPServerPipeline(first: Bool = false,
|
||||
public func configureHTTPServerPipeline(position: ChannelPipeline.Position = .last,
|
||||
withPipeliningAssistance pipelining: Bool = true,
|
||||
withServerUpgrade upgrade: HTTPUpgradeConfiguration? = nil,
|
||||
withErrorHandling errorHandling: Bool = true) -> EventLoopFuture<Void> {
|
||||
@@ -83,7 +82,7 @@ extension ChannelPipeline {
|
||||
handlers.append(upgrader)
|
||||
}
|
||||
|
||||
return self.addHandlers(handlers, first: first)
|
||||
return self.addHandlers(handlers, position: position)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler, RemovableChannelHa
|
||||
ctx.fireChannelReadComplete()
|
||||
}
|
||||
}.whenComplete { (_: Result<Void, Error>) in
|
||||
ctx.pipeline.remove(ctx: ctx, promise: nil)
|
||||
ctx.pipeline.removeHandler(ctx: ctx, promise: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -226,7 +226,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler, RemovableChannelHa
|
||||
private func notUpgrading(ctx: ChannelHandlerContext, data: NIOAny) {
|
||||
assert(self.receivedMessages.count == 0)
|
||||
ctx.fireChannelRead(data)
|
||||
ctx.pipeline.remove(ctx: ctx, promise: nil)
|
||||
ctx.pipeline.removeHandler(ctx: ctx, promise: nil)
|
||||
}
|
||||
|
||||
/// Builds the initial mandatory HTTP headers for HTTP ugprade responses.
|
||||
@@ -237,7 +237,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler, RemovableChannelHa
|
||||
/// Removes the given channel handler from the channel pipeline.
|
||||
private func removeHandler(ctx: ChannelHandlerContext, handler: RemovableChannelHandler?) -> EventLoopFuture<Void> {
|
||||
if let handler = handler {
|
||||
return ctx.pipeline.remove(handler: handler)
|
||||
return ctx.pipeline.removeHandler(handler)
|
||||
} else {
|
||||
return ctx.eventLoop.makeSucceededFuture(())
|
||||
}
|
||||
@@ -249,7 +249,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler, RemovableChannelHa
|
||||
return ctx.eventLoop.makeSucceededFuture(())
|
||||
}
|
||||
|
||||
return .andAllSucceed(self.extraHTTPHandlers.map { ctx.pipeline.remove(handler: $0) },
|
||||
return .andAllSucceed(self.extraHTTPHandlers.map { ctx.pipeline.removeHandler($0) },
|
||||
on: ctx.eventLoop)
|
||||
}
|
||||
}
|
||||
@@ -517,7 +517,7 @@ let bootstrap = ServerBootstrap(group: group)
|
||||
// Set the handlers that are applied to the accepted Channels
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.configureHTTPServerPipeline(withErrorHandling: true).flatMap {
|
||||
channel.pipeline.add(handler: HTTPHandler(fileIO: fileIO, htdocsPath: htdocs))
|
||||
channel.pipeline.addHandler(HTTPHandler(fileIO: fileIO, htdocsPath: htdocs))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,8 +73,8 @@ var datagramBootstrap = DatagramBootstrap(group: group)
|
||||
.channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEPORT), value: 1)
|
||||
.channelInitializer { channel in
|
||||
return channel.pipeline.add(handler: ChatMessageEncoder()).flatMap {
|
||||
channel.pipeline.add(handler: ChatMessageDecoder())
|
||||
return channel.pipeline.addHandler(ChatMessageEncoder()).flatMap {
|
||||
channel.pipeline.addHandler(ChatMessageDecoder())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ let serverChannel = try ServerBootstrap(group: group)
|
||||
.childChannelOption(ChannelOptions.socket(IPPROTO_TCP, TCP_NODELAY), value: 1)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.configureHTTPServerPipeline(withPipeliningAssistance: true).flatMap {
|
||||
channel.pipeline.add(handler: SimpleHTTPServer())
|
||||
channel.pipeline.addHandler(SimpleHTTPServer())
|
||||
}
|
||||
}.bind(host: "127.0.0.1", port: 0).wait()
|
||||
|
||||
@@ -559,9 +559,9 @@ try measureAndPrint(desc: "no-net_http1_10k_reqs_1_conn") {
|
||||
}
|
||||
try channel.pipeline.configureHTTPServerPipeline(withPipeliningAssistance: true,
|
||||
withErrorHandling: true).flatMap {
|
||||
channel.pipeline.add(handler: SimpleHTTPServer())
|
||||
channel.pipeline.addHandler(SimpleHTTPServer())
|
||||
}.flatMap {
|
||||
channel.pipeline.add(handler: measuringHandler, first: true)
|
||||
channel.pipeline.addHandler(measuringHandler, position: .first)
|
||||
}.wait()
|
||||
|
||||
measuringHandler.kickOff(channel: channel)
|
||||
@@ -581,7 +581,7 @@ measureAndPrint(desc: "http1_10k_reqs_1_conn") {
|
||||
.channelOption(ChannelOptions.socket(IPPROTO_TCP, TCP_NODELAY), value: 1)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.addHTTPClientHandlers().flatMap {
|
||||
channel.pipeline.add(handler: repeatedRequestsHandler)
|
||||
channel.pipeline.addHandler(repeatedRequestsHandler)
|
||||
}
|
||||
}
|
||||
.connect(to: serverChannel.localAddress!)
|
||||
@@ -602,7 +602,7 @@ measureAndPrint(desc: "http1_10k_reqs_100_conns") {
|
||||
let clientChannel = try! ClientBootstrap(group: group)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.addHTTPClientHandlers().flatMap {
|
||||
channel.pipeline.add(handler: repeatedRequestsHandler)
|
||||
channel.pipeline.addHandler(repeatedRequestsHandler)
|
||||
}
|
||||
}
|
||||
.connect(to: serverChannel.localAddress!)
|
||||
|
||||
@@ -109,7 +109,7 @@ public class ApplicationProtocolNegotiationHandler: ChannelInboundHandler, Remov
|
||||
let switchFuture = completionHandler(result)
|
||||
switchFuture.whenComplete { (_: Result<Void, Error>) in
|
||||
self.unbuffer(context: context)
|
||||
context.pipeline.remove(handler: self, promise: nil)
|
||||
context.pipeline.removeHandler(self, promise: nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -421,7 +421,7 @@ public class SNIHandler: ByteToMessageDecoder {
|
||||
private func sniComplete(result: SNIResult, ctx: ChannelHandlerContext) {
|
||||
waitingForUser = true
|
||||
completionHandler(result).whenSuccess {
|
||||
ctx.pipeline.remove(ctx: ctx, promise: nil)
|
||||
ctx.pipeline.removeHandler(ctx: ctx, promise: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,12 +147,12 @@ public final class WebSocketUpgrader: HTTPServerProtocolUpgrader {
|
||||
public func upgrade(ctx: ChannelHandlerContext, upgradeRequest: HTTPRequestHead) -> EventLoopFuture<Void> {
|
||||
/// We never use the automatic error handling feature of the WebSocketFrameDecoder: we always use the separate channel
|
||||
/// handler.
|
||||
var upgradeFuture = ctx.pipeline.add(handler: WebSocketFrameEncoder()).flatMap {
|
||||
ctx.pipeline.add(handler: ByteToMessageHandler(WebSocketFrameDecoder(maxFrameSize: self.maxFrameSize, automaticErrorHandling: false)))
|
||||
var upgradeFuture = ctx.pipeline.addHandler(WebSocketFrameEncoder()).flatMap {
|
||||
ctx.pipeline.addHandler(ByteToMessageHandler(WebSocketFrameDecoder(maxFrameSize: self.maxFrameSize, automaticErrorHandling: false)))
|
||||
}
|
||||
|
||||
if self.automaticErrorHandling {
|
||||
upgradeFuture = upgradeFuture.flatMap { ctx.pipeline.add(handler: WebSocketProtocolErrorHandler())}
|
||||
upgradeFuture = upgradeFuture.flatMap { ctx.pipeline.addHandler(WebSocketProtocolErrorHandler())}
|
||||
}
|
||||
|
||||
return upgradeFuture.flatMap {
|
||||
|
||||
@@ -204,7 +204,7 @@ let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
|
||||
|
||||
let upgrader = WebSocketUpgrader(shouldUpgrade: { (head: HTTPRequestHead) in HTTPHeaders() },
|
||||
upgradePipelineHandler: { (channel: Channel, _: HTTPRequestHead) in
|
||||
channel.pipeline.add(handler: WebSocketTimeHandler())
|
||||
channel.pipeline.addHandler(WebSocketTimeHandler())
|
||||
})
|
||||
|
||||
let bootstrap = ServerBootstrap(group: group)
|
||||
@@ -218,11 +218,11 @@ let bootstrap = ServerBootstrap(group: group)
|
||||
let config: HTTPUpgradeConfiguration = (
|
||||
upgraders: [ upgrader ],
|
||||
completionHandler: { _ in
|
||||
channel.pipeline.remove(handler: httpHandler, promise: nil)
|
||||
channel.pipeline.removeHandler(httpHandler, promise: nil)
|
||||
}
|
||||
)
|
||||
return channel.pipeline.configureHTTPServerPipeline(withServerUpgrade: config).flatMap {
|
||||
channel.pipeline.add(handler: httpHandler)
|
||||
channel.pipeline.addHandler(httpHandler)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,57 @@ extension StaticString: Collection {
|
||||
extension ChannelPipeline {
|
||||
@available(*, deprecated, message: "please use ByteToMessageHandler(myByteToMessageDecoder)")
|
||||
public func add<Decoder: ByteToMessageDecoder>(handler decoder: Decoder) -> EventLoopFuture<Void> {
|
||||
return self.add(handler: ByteToMessageHandler(decoder))
|
||||
return self.addHandler(ByteToMessageHandler(decoder))
|
||||
}
|
||||
|
||||
@available(*, deprecated, renamed: "addHandler(_:position:)")
|
||||
public func add(handler: ChannelHandler, first: Bool = false) -> EventLoopFuture<Void> {
|
||||
return self.addHandler(handler, position: first ? .first : .last)
|
||||
}
|
||||
|
||||
@available(*, deprecated, renamed: "addHandler(_:name:position:)")
|
||||
public func add(name: String, handler: ChannelHandler, first: Bool = false) -> EventLoopFuture<Void> {
|
||||
return self.addHandler(handler, name: name, position: first ? .first : .last)
|
||||
}
|
||||
|
||||
@available(*, deprecated, renamed: "addHandler(_:name:position:)")
|
||||
public func add(name: String? = nil, handler: ChannelHandler, after: ChannelHandler) -> EventLoopFuture<Void> {
|
||||
return self.addHandler(handler, name: name, position: .after(after))
|
||||
}
|
||||
|
||||
@available(*, deprecated, renamed: "addHandler(_:name:position:)")
|
||||
public func add(name: String? = nil, handler: ChannelHandler, before: ChannelHandler) -> EventLoopFuture<Void> {
|
||||
return self.addHandler(handler, name: name, position: .before(before))
|
||||
}
|
||||
|
||||
@available(*, deprecated, renamed: "removeHandler(_:)")
|
||||
public func remove(handler: RemovableChannelHandler) -> EventLoopFuture<Void> {
|
||||
return self.removeHandler(handler)
|
||||
}
|
||||
|
||||
@available(*, deprecated, renamed: "removeHandler(name:)")
|
||||
public func remove(name: String) -> EventLoopFuture<Void> {
|
||||
return self.removeHandler(name: name)
|
||||
}
|
||||
|
||||
@available(*, deprecated, renamed: "removeHandler(ctx:)")
|
||||
public func remove(ctx: ChannelHandlerContext) -> EventLoopFuture<Void> {
|
||||
return self.removeHandler(ctx: ctx)
|
||||
}
|
||||
|
||||
@available(*, deprecated, renamed: "removeHandler(_:promise:)")
|
||||
public func remove(handler: RemovableChannelHandler, promise: EventLoopPromise<Void>?) {
|
||||
return self.removeHandler(handler, promise: promise)
|
||||
}
|
||||
|
||||
@available(*, deprecated, renamed: "removeHandler(name:promise:)")
|
||||
public func remove(name: String, promise: EventLoopPromise<Void>?) {
|
||||
return self.removeHandler(name: name, promise: promise)
|
||||
}
|
||||
|
||||
@available(*, deprecated, renamed: "removeHandler(ctx:promise:)")
|
||||
public func remove(ctx: ChannelHandlerContext, promise: EventLoopPromise<Void>?) {
|
||||
return self.removeHandler(ctx: ctx, promise: promise)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -125,11 +125,11 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseDecoder()).wait())
|
||||
|
||||
let handler = ChannelInactiveHandler(eofMechanism)
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: handler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
|
||||
|
||||
// Prime the decoder with a GET and consume it.
|
||||
XCTAssertTrue(try channel.writeOutbound(HTTPClientRequestPart.head(HTTPRequestHead(version: version, method: .GET, uri: "/"))))
|
||||
@@ -188,11 +188,11 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
private func assertIgnoresLengthFields(requestMethod: HTTPMethod,
|
||||
responseStatus: HTTPResponseStatus,
|
||||
responseFramingField: FramingField) throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseDecoder()).wait())
|
||||
|
||||
let handler = MessageEndHandler<HTTPResponseHead, ByteBuffer>()
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: handler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
|
||||
|
||||
// Prime the decoder with a request and consume it.
|
||||
XCTAssertTrue(try channel.writeOutbound(HTTPClientRequestPart.head(HTTPRequestHead(version: .init(major: 1, minor: 1),
|
||||
@@ -292,10 +292,10 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
}
|
||||
|
||||
private func assertRequestTransferEncodingHasNoBody(transferEncodingHeader: String) throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
let handler = MessageEndHandler<HTTPRequestHead, ByteBuffer>()
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: handler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
|
||||
|
||||
// Send a GET with the appropriate Transfer Encoding header.
|
||||
XCTAssertNoThrow(try channel.writeInbound(ByteBuffer(string: "POST / HTTP/1.1\r\nTransfer-Encoding: \(transferEncodingHeader)\r\n\r\n")))
|
||||
@@ -327,11 +327,11 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
}
|
||||
|
||||
private func assertResponseTransferEncodingHasBodyTerminatedByEOF(transferEncodingHeader: String, eofMechanism: EOFMechanism) throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseDecoder()).wait())
|
||||
|
||||
let handler = MessageEndHandler<HTTPResponseHead, ByteBuffer>()
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: handler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
|
||||
|
||||
// Prime the decoder with a request and consume it.
|
||||
XCTAssertTrue(try channel.writeOutbound(HTTPClientRequestPart.head(HTTPRequestHead(version: .init(major: 1, minor: 1),
|
||||
@@ -398,7 +398,7 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testRequestWithTEAndContentLengthErrors() throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
// Send a GET with the invalid headers.
|
||||
do {
|
||||
@@ -416,8 +416,8 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testResponseWithTEAndContentLengthErrors() throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseDecoder()).wait())
|
||||
|
||||
// Prime the decoder with a request.
|
||||
XCTAssertTrue(try channel.writeOutbound(HTTPClientRequestPart.head(HTTPRequestHead(version: .init(major: 1, minor: 1),
|
||||
@@ -440,7 +440,7 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
}
|
||||
|
||||
private func assertRequestWithInvalidCLErrors(contentLengthField: String) throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
// Send a GET with the invalid headers.
|
||||
do {
|
||||
@@ -474,7 +474,7 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
func testRequestWithIdenticalContentLengthRepeatedErrors() throws {
|
||||
// This is another case where http_parser is, if not wrong, then aggressively interpreting
|
||||
// the spec. Regardless, we match it.
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
// Send two POSTs with repeated content length, one with one field and one with two.
|
||||
// Both should error.
|
||||
@@ -495,7 +495,7 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
func testRequestWithMultipleIdenticalContentLengthFieldsErrors() throws {
|
||||
// This is another case where http_parser is, if not wrong, then aggressively interpreting
|
||||
// the spec. Regardless, we match it.
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
do {
|
||||
try channel.writeInbound(ByteBuffer(string: "POST / HTTP/1.1\r\nContent-Length: 4\r\nContent-Length: 4\r\n\r\n"))
|
||||
@@ -512,10 +512,10 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testRequestWithoutExplicitLengthIsZeroLength() throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
let handler = MessageEndHandler<HTTPRequestHead, ByteBuffer>()
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: handler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
|
||||
|
||||
// Send a POST without a length field of any kind. This should be a zero-length request,
|
||||
// so .end should come immediately.
|
||||
|
||||
@@ -31,7 +31,7 @@ class HTTPDecoderTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testDoesNotDecodeRealHTTP09Request() throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
// This is an invalid HTTP/0.9 simple request (too many CRLFs), but we need to
|
||||
// trigger https://github.com/nodejs/http-parser/issues/386 or http_parser won't
|
||||
@@ -52,7 +52,7 @@ class HTTPDecoderTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testDoesNotDecodeFakeHTTP09Request() throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
// This is a HTTP/1.1-formatted request that claims to be HTTP/0.9.
|
||||
var buffer = channel.allocator.buffer(capacity: 64)
|
||||
@@ -71,7 +71,7 @@ class HTTPDecoderTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testDoesNotDecodeHTTP2XRequest() throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
// This is a hypothetical HTTP/2.0 protocol request, assuming it is
|
||||
// byte for byte identical (which such a protocol would never be).
|
||||
@@ -91,7 +91,7 @@ class HTTPDecoderTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testToleratesHTTP13Request() throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
// We tolerate higher versions of HTTP/1 than we know about because RFC 7230
|
||||
// says that these should be treated like HTTP/1.1 by our users.
|
||||
@@ -103,8 +103,8 @@ class HTTPDecoderTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testDoesNotDecodeRealHTTP09Response() throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseDecoder()).wait())
|
||||
|
||||
// We need to prime the decoder by seeing a GET request.
|
||||
try channel.writeOutbound(HTTPClientRequestPart.head(HTTPRequestHead(version: .init(major: 0, minor: 9), method: .GET, uri: "/")))
|
||||
@@ -127,8 +127,8 @@ class HTTPDecoderTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testDoesNotDecodeFakeHTTP09Response() throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseDecoder()).wait())
|
||||
|
||||
// We need to prime the decoder by seeing a GET request.
|
||||
try channel.writeOutbound(HTTPClientRequestPart.head(HTTPRequestHead(version: .init(major: 0, minor: 9), method: .GET, uri: "/")))
|
||||
@@ -150,8 +150,8 @@ class HTTPDecoderTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testDoesNotDecodeHTTP2XResponse() throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseDecoder()).wait())
|
||||
|
||||
// We need to prime the decoder by seeing a GET request.
|
||||
try channel.writeOutbound(HTTPClientRequestPart.head(HTTPRequestHead(version: .init(major: 2, minor: 0), method: .GET, uri: "/")))
|
||||
@@ -174,8 +174,8 @@ class HTTPDecoderTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testToleratesHTTP13Response() throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseDecoder()).wait())
|
||||
|
||||
// We need to prime the decoder by seeing a GET request.
|
||||
try channel.writeOutbound(HTTPClientRequestPart.head(HTTPRequestHead(version: .init(major: 2, minor: 0), method: .GET, uri: "/")))
|
||||
@@ -208,8 +208,8 @@ class HTTPDecoderTest: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: Receiver()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(Receiver()).wait())
|
||||
|
||||
// This is a hypothetical HTTP/2.0 protocol response, assuming it is
|
||||
// byte for byte identical (which such a protocol would never be).
|
||||
@@ -241,14 +241,14 @@ class HTTPDecoderTest: XCTestCase {
|
||||
switch part {
|
||||
case .end:
|
||||
// ignore
|
||||
_ = ctx.pipeline.remove(name: "decoder")
|
||||
_ = ctx.pipeline.removeHandler(name: "decoder")
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
XCTAssertNoThrow(try channel.pipeline.add(name: "decoder", handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: Receiver()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder(), name: "decoder").wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(Receiver()).wait())
|
||||
|
||||
var buffer = channel.allocator.buffer(capacity: 64)
|
||||
buffer.writeStaticString("OPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: myproto\r\nConnection: upgrade\r\n\r\nXXXX")
|
||||
@@ -270,7 +270,7 @@ class HTTPDecoderTest: XCTestCase {
|
||||
}
|
||||
|
||||
func handlerAdded(ctx: ChannelHandlerContext) {
|
||||
_ = ctx.pipeline.remove(name: "decoder")
|
||||
_ = ctx.pipeline.removeHandler(name: "decoder")
|
||||
}
|
||||
|
||||
func handlerRemoved(ctx: ChannelHandlerContext) {
|
||||
@@ -286,8 +286,8 @@ class HTTPDecoderTest: XCTestCase {
|
||||
let part = self.unwrapInboundIn(data)
|
||||
switch part {
|
||||
case .end:
|
||||
_ = ctx.pipeline.remove(handler: self).flatMap { _ in
|
||||
ctx.pipeline.add(handler: self.collector)
|
||||
_ = ctx.pipeline.removeHandler(self).flatMap { _ in
|
||||
ctx.pipeline.addHandler(self.collector)
|
||||
}
|
||||
default:
|
||||
// ignore
|
||||
@@ -295,8 +295,9 @@ class HTTPDecoderTest: XCTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
XCTAssertNoThrow(try channel.pipeline.add(name: "decoder", handler: HTTPRequestDecoder(leftOverBytesStrategy: .forwardBytes)).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: Receiver()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder(leftOverBytesStrategy: .forwardBytes),
|
||||
name: "decoder").wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(Receiver()).wait())
|
||||
|
||||
// This connect call is semantically wrong, but it's how you active embedded channels properly right now.
|
||||
XCTAssertNoThrow(try channel.connect(to: SocketAddress(ipAddress: "127.0.0.1", port: 8888)).wait())
|
||||
@@ -321,7 +322,7 @@ class HTTPDecoderTest: XCTestCase {
|
||||
}
|
||||
|
||||
func handlerAdded(ctx: ChannelHandlerContext) {
|
||||
_ = ctx.pipeline.remove(name: "decoder")
|
||||
_ = ctx.pipeline.removeHandler(name: "decoder")
|
||||
}
|
||||
|
||||
func handlerRemoved(ctx: ChannelHandlerContext) {
|
||||
@@ -347,8 +348,8 @@ class HTTPDecoderTest: XCTestCase {
|
||||
let part = self.unwrapInboundIn(data)
|
||||
switch part {
|
||||
case .end:
|
||||
_ = ctx.pipeline.remove(handler: self).flatMap { _ in
|
||||
ctx.pipeline.add(handler: ByteCollector())
|
||||
_ = ctx.pipeline.removeHandler(self).flatMap { _ in
|
||||
ctx.pipeline.addHandler(ByteCollector())
|
||||
}
|
||||
break
|
||||
default:
|
||||
@@ -358,8 +359,9 @@ class HTTPDecoderTest: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.add(name: "decoder", handler: HTTPResponseDecoder(leftOverBytesStrategy: .forwardBytes)).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: Receiver()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseDecoder(leftOverBytesStrategy: .forwardBytes),
|
||||
name: "decoder").wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(Receiver()).wait())
|
||||
|
||||
XCTAssertNoThrow(try channel.connect(to: SocketAddress(ipAddress: "127.0.0.1", port: 8888)).wait())
|
||||
|
||||
@@ -372,7 +374,7 @@ class HTTPDecoderTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testExtraCRLF() throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
// This is a simple HTTP/1.1 request with a few too many CRLFs before it, to trigger
|
||||
// https://github.com/nodejs/http-parser/pull/432.
|
||||
@@ -401,7 +403,7 @@ class HTTPDecoderTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testSOURCEDoesntExplodeUs() throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
// This is a simple HTTP/1.1 request with the SOURCE verb which is newly added to
|
||||
// http_parser.
|
||||
@@ -430,7 +432,7 @@ class HTTPDecoderTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testExtraCarriageReturnBetweenSubsequentRequests() throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
// This is a simple HTTP/1.1 request with an extra \r between first and second message, designed to hit the code
|
||||
// changed in https://github.com/nodejs/http-parser/pull/432 .
|
||||
|
||||
@@ -29,7 +29,7 @@ class HTTPRequestEncoderTests: XCTestCase {
|
||||
XCTAssertEqual(.some(false), try? channel.finish())
|
||||
}
|
||||
|
||||
try channel.pipeline.add(handler: HTTPRequestEncoder()).wait()
|
||||
try channel.pipeline.addHandler(HTTPRequestEncoder()).wait()
|
||||
var request = HTTPRequestHead(version: HTTPVersion(major: 1, minor:1), method: method, uri: "/uri")
|
||||
request.headers = headers
|
||||
try channel.writeOutbound(HTTPClientRequestPart.head(request))
|
||||
@@ -78,7 +78,7 @@ class HTTPRequestEncoderTests: XCTestCase {
|
||||
XCTAssertEqual(.some(false), try? channel.finish())
|
||||
}
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestEncoder()).wait())
|
||||
|
||||
// This request contains neither Transfer-Encoding: chunked or Content-Length.
|
||||
let request = HTTPRequestHead(version: HTTPVersion(major: 1, minor:0), method: .GET, uri: "/uri")
|
||||
@@ -94,7 +94,7 @@ class HTTPRequestEncoderTests: XCTestCase {
|
||||
XCTAssertEqual(.some(false), try? channel.finish())
|
||||
}
|
||||
|
||||
try channel.pipeline.add(handler: HTTPRequestEncoder()).wait()
|
||||
try channel.pipeline.addHandler(HTTPRequestEncoder()).wait()
|
||||
var request = HTTPRequestHead(version: HTTPVersion(major: 1, minor:1), method: .POST, uri: "/uri")
|
||||
request.headers.add(name: "content-length", value: "4")
|
||||
|
||||
@@ -117,7 +117,7 @@ class HTTPRequestEncoderTests: XCTestCase {
|
||||
}
|
||||
|
||||
let uri = "server.example.com:80"
|
||||
try channel.pipeline.add(handler: HTTPRequestEncoder()).wait()
|
||||
try channel.pipeline.addHandler(HTTPRequestEncoder()).wait()
|
||||
var request = HTTPRequestHead(version: HTTPVersion(major: 1, minor:1), method: .CONNECT, uri: uri)
|
||||
request.headers.add(name: "Host", value: uri)
|
||||
|
||||
|
||||
@@ -333,8 +333,8 @@ class HTTPResponseCompressorTest: XCTestCase {
|
||||
|
||||
private func compressionChannel() throws -> EmbeddedChannel {
|
||||
let channel = EmbeddedChannel()
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseCompressor()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseCompressor()).wait())
|
||||
return channel
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class HTTPResponseEncoderTests: XCTestCase {
|
||||
XCTAssertEqual(.some(false), try? channel.finish())
|
||||
}
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseEncoder()).wait())
|
||||
var switchingResponse = HTTPResponseHead(version: HTTPVersion(major: 1, minor:1), status: status)
|
||||
switchingResponse.headers = headers
|
||||
XCTAssertNoThrow(try channel.writeOutbound(HTTPServerResponsePart.head(switchingResponse)))
|
||||
@@ -98,7 +98,7 @@ class HTTPResponseEncoderTests: XCTestCase {
|
||||
XCTAssertEqual(.some(false), try? channel.finish())
|
||||
}
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseEncoder()).wait())
|
||||
|
||||
// This response contains neither Transfer-Encoding: chunked or Content-Length.
|
||||
let response = HTTPResponseHead(version: HTTPVersion(major: 1, minor:0), status: .ok)
|
||||
|
||||
@@ -338,7 +338,7 @@ class HTTPServerClientTest : XCTestCase {
|
||||
.childChannelInitializer { channel in
|
||||
// Ensure we don't read faster then we can write by adding the BackPressureHandler into the pipeline.
|
||||
channel.pipeline.configureHTTPServerPipeline(withPipeliningAssistance: false).flatMap {
|
||||
channel.pipeline.add(handler: httpHandler)
|
||||
channel.pipeline.addHandler(httpHandler)
|
||||
}
|
||||
}.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
@@ -349,7 +349,7 @@ class HTTPServerClientTest : XCTestCase {
|
||||
let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.addHTTPClientHandlers().flatMap {
|
||||
channel.pipeline.add(handler: accumulation)
|
||||
channel.pipeline.addHandler(accumulation)
|
||||
}
|
||||
}
|
||||
.connect(to: serverChannel.localAddress!)
|
||||
@@ -396,7 +396,7 @@ class HTTPServerClientTest : XCTestCase {
|
||||
.childChannelInitializer { channel in
|
||||
// Ensure we don't read faster then we can write by adding the BackPressureHandler into the pipeline.
|
||||
channel.pipeline.configureHTTPServerPipeline(withPipeliningAssistance: false).flatMap {
|
||||
channel.pipeline.add(handler: httpHandler)
|
||||
channel.pipeline.addHandler(httpHandler)
|
||||
}
|
||||
}.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
@@ -407,7 +407,7 @@ class HTTPServerClientTest : XCTestCase {
|
||||
let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.addHTTPClientHandlers().flatMap {
|
||||
channel.pipeline.add(handler: accumulation)
|
||||
channel.pipeline.addHandler(accumulation)
|
||||
}
|
||||
}
|
||||
.connect(to: serverChannel.localAddress!)
|
||||
@@ -454,7 +454,7 @@ class HTTPServerClientTest : XCTestCase {
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.configureHTTPServerPipeline(withPipeliningAssistance: false).flatMap {
|
||||
channel.pipeline.add(handler: httpHandler)
|
||||
channel.pipeline.addHandler(httpHandler)
|
||||
}
|
||||
}.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
@@ -465,7 +465,7 @@ class HTTPServerClientTest : XCTestCase {
|
||||
let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.addHTTPClientHandlers().flatMap {
|
||||
channel.pipeline.add(handler: accumulation)
|
||||
channel.pipeline.addHandler(accumulation)
|
||||
}
|
||||
}
|
||||
.connect(to: serverChannel.localAddress!)
|
||||
@@ -513,7 +513,7 @@ class HTTPServerClientTest : XCTestCase {
|
||||
.childChannelInitializer { channel in
|
||||
// Ensure we don't read faster then we can write by adding the BackPressureHandler into the pipeline.
|
||||
channel.pipeline.configureHTTPServerPipeline(withPipeliningAssistance: false).flatMap {
|
||||
channel.pipeline.add(handler: httpHandler)
|
||||
channel.pipeline.addHandler(httpHandler)
|
||||
}
|
||||
}.bind(host: "127.0.0.1", port: 0).wait())
|
||||
defer {
|
||||
@@ -521,7 +521,7 @@ class HTTPServerClientTest : XCTestCase {
|
||||
}
|
||||
|
||||
let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group)
|
||||
.channelInitializer({ $0.pipeline.add(handler: accumulation) })
|
||||
.channelInitializer({ $0.pipeline.addHandler(accumulation) })
|
||||
.connect(to: serverChannel.localAddress!)
|
||||
.wait())
|
||||
defer {
|
||||
@@ -553,7 +553,7 @@ class HTTPServerClientTest : XCTestCase {
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.configureHTTPServerPipeline(withPipeliningAssistance: false).flatMap {
|
||||
channel.pipeline.add(handler: httpHandler)
|
||||
channel.pipeline.addHandler(httpHandler)
|
||||
}
|
||||
}.bind(host: "127.0.0.1", port: 0).wait())
|
||||
defer {
|
||||
@@ -563,7 +563,7 @@ class HTTPServerClientTest : XCTestCase {
|
||||
let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.addHTTPClientHandlers().flatMap {
|
||||
channel.pipeline.add(handler: accumulation)
|
||||
channel.pipeline.addHandler(accumulation)
|
||||
}
|
||||
}
|
||||
.connect(to: serverChannel.localAddress!)
|
||||
@@ -598,7 +598,7 @@ class HTTPServerClientTest : XCTestCase {
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.configureHTTPServerPipeline(withPipeliningAssistance: false).flatMap {
|
||||
channel.pipeline.add(handler: httpHandler)
|
||||
channel.pipeline.addHandler(httpHandler)
|
||||
}
|
||||
}.bind(host: "127.0.0.1", port: 0).wait())
|
||||
defer {
|
||||
@@ -608,7 +608,7 @@ class HTTPServerClientTest : XCTestCase {
|
||||
let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.addHTTPClientHandlers().flatMap {
|
||||
channel.pipeline.add(handler: accumulation)
|
||||
channel.pipeline.addHandler(accumulation)
|
||||
}
|
||||
}
|
||||
.connect(to: serverChannel.localAddress!)
|
||||
|
||||
@@ -96,11 +96,11 @@ class HTTPServerPipelineHandlerTest: XCTestCase {
|
||||
self.readRecorder = ReadRecorder()
|
||||
self.readCounter = ReadCountingHandler()
|
||||
self.writeRecorder = WriteRecorder()
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: self.readCounter).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: self.writeRecorder).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPServerPipelineHandler()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: self.readRecorder).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(self.readCounter).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(self.writeRecorder).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPServerPipelineHandler()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(self.readRecorder).wait())
|
||||
|
||||
self.requestHead = HTTPRequestHead(version: .init(major: 1, minor: 1), method: .GET, uri: "/path")
|
||||
self.requestHead.headers.add(name: "Host", value: "example.com")
|
||||
@@ -460,7 +460,7 @@ class HTTPServerPipelineHandlerTest: XCTestCase {
|
||||
}
|
||||
|
||||
let handler = VerifyOrderHandler()
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: handler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
|
||||
|
||||
for f in 1...3 {
|
||||
XCTAssertNoThrow(try self.channel.writeInbound(HTTPServerRequestPart.head(makeRequestHead(uri: "/req_\(f)"))))
|
||||
@@ -730,8 +730,8 @@ class HTTPServerPipelineHandlerTest: XCTestCase {
|
||||
}
|
||||
|
||||
let handler = VerifyOrderHandler()
|
||||
XCTAssertNoThrow(try self.channel.pipeline.add(handler: HTTPServerProtocolErrorHandler()).wait())
|
||||
XCTAssertNoThrow(try self.channel.pipeline.add(handler: handler).wait())
|
||||
XCTAssertNoThrow(try self.channel.pipeline.addHandler(HTTPServerProtocolErrorHandler()).wait())
|
||||
XCTAssertNoThrow(try self.channel.pipeline.addHandler(handler).wait())
|
||||
|
||||
self.channel.pipeline.fireErrorCaught(HTTPParserError.headerOverflow)
|
||||
|
||||
@@ -790,8 +790,8 @@ class HTTPServerPipelineHandlerTest: XCTestCase {
|
||||
}
|
||||
|
||||
let handler = VerifyOrderHandler()
|
||||
XCTAssertNoThrow(try self.channel.pipeline.add(handler: HTTPServerProtocolErrorHandler()).wait())
|
||||
XCTAssertNoThrow(try self.channel.pipeline.add(handler: handler).wait())
|
||||
XCTAssertNoThrow(try self.channel.pipeline.addHandler(HTTPServerProtocolErrorHandler()).wait())
|
||||
XCTAssertNoThrow(try self.channel.pipeline.addHandler(handler).wait())
|
||||
|
||||
XCTAssertNoThrow(try self.channel.writeInbound(HTTPServerRequestPart.head(makeRequestHead(uri: "/one"))))
|
||||
XCTAssertNoThrow(try self.channel.writeInbound(HTTPServerRequestPart.end(nil)))
|
||||
|
||||
@@ -114,7 +114,7 @@ class HTTPServerProtocolErrorHandlerTest: XCTestCase {
|
||||
}
|
||||
let channel = EmbeddedChannel()
|
||||
XCTAssertNoThrow(try channel.pipeline.configureHTTPServerPipeline(withErrorHandling: true).flatMap {
|
||||
channel.pipeline.add(handler: DelayWriteHandler())
|
||||
channel.pipeline.addHandler(DelayWriteHandler())
|
||||
}.wait())
|
||||
|
||||
var buffer = channel.allocator.buffer(capacity: 1024)
|
||||
|
||||
@@ -78,10 +78,10 @@ class HTTPTest: XCTestCase {
|
||||
defer {
|
||||
XCTAssertNoThrow(try channel.finish())
|
||||
}
|
||||
try channel.pipeline.add(handler: HTTPRequestDecoder()).wait()
|
||||
try channel.pipeline.addHandler(HTTPRequestDecoder()).wait()
|
||||
var bodyData: [UInt8]? = nil
|
||||
var allBodyDatas: [[UInt8]] = []
|
||||
try channel.pipeline.add(handler: TestChannelInboundHandler { reqPart in
|
||||
try channel.pipeline.addHandler(TestChannelInboundHandler { reqPart in
|
||||
switch reqPart {
|
||||
case .head(var req):
|
||||
XCTAssertEqual((index * 2), step)
|
||||
|
||||
@@ -84,7 +84,7 @@ private func serverHTTPChannelWithAutoremoval(group: EventLoopGroup,
|
||||
p.succeed(channel)
|
||||
let upgradeConfig = (upgraders: upgraders, completionHandler: upgradeCompletionHandler)
|
||||
return channel.pipeline.configureHTTPServerPipeline(withPipeliningAssistance: pipelining, withServerUpgrade: upgradeConfig).flatMap {
|
||||
let futureResults = extraHandlers.map { channel.pipeline.add(handler: $0) }
|
||||
let futureResults = extraHandlers.map { channel.pipeline.addHandler($0) }
|
||||
return EventLoopFuture.andAllSucceed(futureResults, on: channel.eventLoop)
|
||||
}
|
||||
}.bind(host: "127.0.0.1", port: 0).wait()
|
||||
@@ -354,7 +354,7 @@ class HTTPUpgradeTestCase: XCTestCase {
|
||||
}
|
||||
let data = HTTPServerRequestPart.body(ByteBuffer.forString("hello"))
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: handler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
|
||||
|
||||
do {
|
||||
try channel.writeInbound(data)
|
||||
@@ -402,7 +402,7 @@ class HTTPUpgradeTestCase: XCTestCase {
|
||||
expectedResponseHeaders: ["X-Upgrade-Complete: true", "upgrade: myproto", "connection: upgrade"])
|
||||
completePromise.succeed(())
|
||||
}
|
||||
XCTAssertNoThrow(try client.pipeline.add(handler: clientHandler).wait())
|
||||
XCTAssertNoThrow(try client.pipeline.addHandler(clientHandler).wait())
|
||||
|
||||
// This request is safe to upgrade.
|
||||
let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: myproto\r\nKafkaesque: yup\r\nConnection: upgrade\r\nConnection: kafkaesque\r\n\r\n"
|
||||
@@ -507,7 +507,7 @@ class HTTPUpgradeTestCase: XCTestCase {
|
||||
expectedResponseHeaders: ["X-Upgrade-Complete: true", "upgrade: myproto", "connection: upgrade"])
|
||||
completePromise.succeed(())
|
||||
}
|
||||
XCTAssertNoThrow(try client.pipeline.add(handler: clientHandler).wait())
|
||||
XCTAssertNoThrow(try client.pipeline.addHandler(clientHandler).wait())
|
||||
|
||||
// This request is safe to upgrade.
|
||||
let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: myproto, exploder\r\nKafkaesque: yup\r\nConnection: upgrade, kafkaesque\r\n\r\n"
|
||||
@@ -551,7 +551,7 @@ class HTTPUpgradeTestCase: XCTestCase {
|
||||
expectedResponseHeaders: ["X-Upgrade-Complete: true", "upgrade: myproto", "connection: upgrade"])
|
||||
completePromise.succeed(())
|
||||
}
|
||||
XCTAssertNoThrow(try client.pipeline.add(handler: clientHandler).wait())
|
||||
XCTAssertNoThrow(try client.pipeline.addHandler(clientHandler).wait())
|
||||
|
||||
// This request is safe to upgrade.
|
||||
let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: myproto\r\nKafkaesque: yup\r\nConnection: upgrade,kafkaesque\r\n\r\n"
|
||||
@@ -612,7 +612,7 @@ class HTTPUpgradeTestCase: XCTestCase {
|
||||
expectedResponseHeaders: ["X-Upgrade-Complete: true", "upgrade: myproto", "connection: upgrade"])
|
||||
completePromise.succeed(())
|
||||
}
|
||||
XCTAssertNoThrow(try client.pipeline.add(handler: clientHandler).wait())
|
||||
XCTAssertNoThrow(try client.pipeline.addHandler(clientHandler).wait())
|
||||
|
||||
// This request is safe to upgrade.
|
||||
let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: noproto,myproto\r\nKafkaesque: yup\r\nConnection: upgrade, kafkaesque\r\n\r\n"
|
||||
@@ -658,7 +658,7 @@ class HTTPUpgradeTestCase: XCTestCase {
|
||||
expectedResponseHeaders: ["X-Upgrade-Complete: true", "upgrade: myproto", "connection: upgrade"])
|
||||
completePromise.succeed(())
|
||||
}
|
||||
XCTAssertNoThrow(try client.pipeline.add(handler: clientHandler).wait())
|
||||
XCTAssertNoThrow(try client.pipeline.addHandler(clientHandler).wait())
|
||||
|
||||
// This request is safe to upgrade.
|
||||
let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: myproto\r\nWeirdcase: yup\r\nConnection: upgrade,weirdcase\r\n\r\n"
|
||||
@@ -692,7 +692,7 @@ class HTTPUpgradeTestCase: XCTestCase {
|
||||
expectedResponseHeaders: ["X-Upgrade-Complete: true", "upgrade: myproto", "connection: upgrade"])
|
||||
completePromise.succeed(())
|
||||
}
|
||||
XCTAssertNoThrow(try client.pipeline.add(handler: clientHandler).wait())
|
||||
XCTAssertNoThrow(try client.pipeline.addHandler(clientHandler).wait())
|
||||
|
||||
// This request is safe to upgrade.
|
||||
let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: myproto\r\nConnection: upgrade\r\n\r\n"
|
||||
@@ -735,7 +735,7 @@ class HTTPUpgradeTestCase: XCTestCase {
|
||||
expectedResponseHeaders: ["X-Upgrade-Complete: true", "upgrade: myproto", "connection: upgrade"])
|
||||
completePromise.succeed(())
|
||||
}
|
||||
XCTAssertNoThrow(try client.pipeline.add(handler: clientHandler).wait())
|
||||
XCTAssertNoThrow(try client.pipeline.addHandler(clientHandler).wait())
|
||||
|
||||
// This request is safe to upgrade, but is immediately followed by non-HTTP data that will probably
|
||||
// blow up the HTTP parser.
|
||||
@@ -885,7 +885,7 @@ class HTTPUpgradeTestCase: XCTestCase {
|
||||
XCTAssertNil(upgradeRequest)
|
||||
upgradeHandlerCbFired = true
|
||||
|
||||
_ = ctx.channel.pipeline.add(handler: CheckWeReadInlineAndExtraData(firstByteDonePromise: firstByteDonePromise,
|
||||
_ = ctx.channel.pipeline.addHandler(CheckWeReadInlineAndExtraData(firstByteDonePromise: firstByteDonePromise,
|
||||
secondByteDonePromise: secondByteDonePromise,
|
||||
allDonePromise: allDonePromise))
|
||||
}
|
||||
@@ -901,7 +901,7 @@ class HTTPUpgradeTestCase: XCTestCase {
|
||||
expectedResponseHeaders: ["X-Upgrade-Complete: true", "upgrade: myproto", "connection: upgrade"])
|
||||
completePromise.succeed(())
|
||||
}
|
||||
XCTAssertNoThrow(try client.pipeline.add(handler: clientHandler).wait())
|
||||
XCTAssertNoThrow(try client.pipeline.addHandler(clientHandler).wait())
|
||||
|
||||
// This request is safe to upgrade.
|
||||
var request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: myproto\r\nKafkaesque: yup\r\nConnection: upgrade\r\nConnection: kafkaesque\r\n\r\n"
|
||||
|
||||
@@ -43,7 +43,7 @@ class ApplicationProtocolNegotiationHandlerTests: XCTestCase {
|
||||
return loop.makeSucceededFuture(())
|
||||
}
|
||||
|
||||
try channel.pipeline.add(handler: handler).wait()
|
||||
try channel.pipeline.addHandler(handler).wait()
|
||||
|
||||
// Fire a pair of events that should be ignored.
|
||||
channel.pipeline.fireUserInboundEventTriggered(EventType.basic)
|
||||
@@ -69,7 +69,7 @@ class ApplicationProtocolNegotiationHandlerTests: XCTestCase {
|
||||
return continuePromise.futureResult
|
||||
}
|
||||
|
||||
try channel.pipeline.add(handler: handler).wait()
|
||||
try channel.pipeline.addHandler(handler).wait()
|
||||
|
||||
// Fire the handshake complete event.
|
||||
channel.pipeline.fireUserInboundEventTriggered(TLSUserEvent.handshakeCompleted(negotiatedProtocol: "h2"))
|
||||
@@ -105,7 +105,7 @@ class ApplicationProtocolNegotiationHandlerTests: XCTestCase {
|
||||
return loop.makeSucceededFuture(())
|
||||
}
|
||||
|
||||
try channel.pipeline.add(handler: handler).wait()
|
||||
try channel.pipeline.addHandler(handler).wait()
|
||||
|
||||
// The data we write should not be buffered.
|
||||
try channel.writeInbound("hello")
|
||||
@@ -123,7 +123,7 @@ class ApplicationProtocolNegotiationHandlerTests: XCTestCase {
|
||||
continuePromise.futureResult
|
||||
}
|
||||
|
||||
try channel.pipeline.add(handler: handler).wait()
|
||||
try channel.pipeline.addHandler(handler).wait()
|
||||
|
||||
// Fire in the event.
|
||||
channel.pipeline.fireUserInboundEventTriggered(TLSUserEvent.handshakeCompleted(negotiatedProtocol: "h2"))
|
||||
@@ -155,8 +155,8 @@ class ApplicationProtocolNegotiationHandlerTests: XCTestCase {
|
||||
}
|
||||
let readCompleteHandler = ReadCompletedHandler()
|
||||
|
||||
try channel.pipeline.add(handler: handler).wait()
|
||||
try channel.pipeline.add(handler: readCompleteHandler).wait()
|
||||
try channel.pipeline.addHandler(handler).wait()
|
||||
try channel.pipeline.addHandler(readCompleteHandler).wait()
|
||||
|
||||
// Fire in the event.
|
||||
channel.pipeline.fireUserInboundEventTriggered(TLSUserEvent.handshakeCompleted(negotiatedProtocol: "h2"))
|
||||
@@ -182,8 +182,8 @@ class ApplicationProtocolNegotiationHandlerTests: XCTestCase {
|
||||
}
|
||||
let readCompleteHandler = ReadCompletedHandler()
|
||||
|
||||
try channel.pipeline.add(handler: handler).wait()
|
||||
try channel.pipeline.add(handler: readCompleteHandler).wait()
|
||||
try channel.pipeline.addHandler(handler).wait()
|
||||
try channel.pipeline.addHandler(readCompleteHandler).wait()
|
||||
|
||||
// Fire in the event.
|
||||
channel.pipeline.fireUserInboundEventTriggered(TLSUserEvent.handshakeCompleted(negotiatedProtocol: "h2"))
|
||||
|
||||
@@ -270,7 +270,7 @@ class SNIHandlerTest: XCTestCase {
|
||||
return continuePromise.futureResult
|
||||
})
|
||||
|
||||
try channel.pipeline.add(handler: handler).wait()
|
||||
try channel.pipeline.addHandler(handler).wait()
|
||||
|
||||
// The handler will run when the last byte of the extension data is sent.
|
||||
// We don't know when that is, so don't try to predict it. However,
|
||||
@@ -321,7 +321,7 @@ class SNIHandlerTest: XCTestCase {
|
||||
return continuePromise.futureResult
|
||||
})
|
||||
|
||||
try channel.pipeline.add(handler: handler).wait()
|
||||
try channel.pipeline.addHandler(handler).wait()
|
||||
|
||||
// Ok, let's go.
|
||||
try channel.writeInbound(buffer)
|
||||
@@ -361,7 +361,7 @@ class SNIHandlerTest: XCTestCase {
|
||||
return loop.makeSucceededFuture(())
|
||||
})
|
||||
|
||||
try channel.pipeline.add(handler: handler).wait()
|
||||
try channel.pipeline.addHandler(handler).wait()
|
||||
|
||||
// Ok, let's go.
|
||||
try channel.writeInbound(buffer)
|
||||
|
||||
@@ -95,7 +95,7 @@ public class AcceptBackoffHandlerTest: XCTestCase {
|
||||
return readCountHandler.readCount
|
||||
}.wait())
|
||||
|
||||
XCTAssertNoThrow(try serverChannel.pipeline.remove(name: acceptHandlerName).wait())
|
||||
XCTAssertNoThrow(try serverChannel.pipeline.removeHandler(name: acceptHandlerName).wait())
|
||||
|
||||
if read {
|
||||
// Removal should have triggered a read.
|
||||
@@ -174,7 +174,7 @@ public class AcceptBackoffHandlerTest: XCTestCase {
|
||||
}, errors: [ENFILE])
|
||||
|
||||
let inactiveVerificationHandler = InactiveVerificationHandler(promise: serverChannel.eventLoop.makePromise())
|
||||
XCTAssertNoThrow(try serverChannel.pipeline.add(handler: inactiveVerificationHandler).wait())
|
||||
XCTAssertNoThrow(try serverChannel.pipeline.addHandler(inactiveVerificationHandler).wait())
|
||||
|
||||
XCTAssertEqual(0, try serverChannel.eventLoop.submit {
|
||||
serverChannel.readable()
|
||||
@@ -253,8 +253,9 @@ public class AcceptBackoffHandlerTest: XCTestCase {
|
||||
group: group))
|
||||
|
||||
XCTAssertNoThrow(try serverChannel.setOption(ChannelOptions.autoRead, value: false).wait())
|
||||
XCTAssertNoThrow(try serverChannel.pipeline.add(handler: readCountHandler).flatMap { _ in
|
||||
serverChannel.pipeline.add(name: self.acceptHandlerName, handler: AcceptBackoffHandler(backoffProvider: backoffProvider))
|
||||
XCTAssertNoThrow(try serverChannel.pipeline.addHandler(readCountHandler).flatMap { _ in
|
||||
serverChannel.pipeline.addHandler(AcceptBackoffHandler(backoffProvider: backoffProvider),
|
||||
name: self.acceptHandlerName)
|
||||
}.wait())
|
||||
|
||||
XCTAssertNoThrow(try eventLoop.submit {
|
||||
|
||||
@@ -296,17 +296,17 @@ class ChannelNotificationTest: XCTestCase {
|
||||
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.serverChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: ServerSocketChannelLifecycleVerificationHandler())
|
||||
channel.pipeline.addHandler(ServerSocketChannelLifecycleVerificationHandler())
|
||||
}
|
||||
.childChannelOption(ChannelOptions.autoRead, value: false)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: AcceptedSocketChannelLifecycleVerificationHandler(acceptedChannelPromise))
|
||||
channel.pipeline.addHandler(AcceptedSocketChannelLifecycleVerificationHandler(acceptedChannelPromise))
|
||||
}
|
||||
.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.add(handler: SocketChannelLifecycleVerificationHandler())
|
||||
channel.pipeline.addHandler(SocketChannelLifecycleVerificationHandler())
|
||||
}
|
||||
.connect(to: serverChannel.localAddress!).wait())
|
||||
XCTAssertNoThrow(try clientChannel.close().wait())
|
||||
@@ -379,7 +379,7 @@ class ChannelNotificationTest: XCTestCase {
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelOption(ChannelOptions.autoRead, value: true)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: OrderVerificationHandler(promise))
|
||||
channel.pipeline.addHandler(OrderVerificationHandler(promise))
|
||||
}
|
||||
.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ extension ChannelPipelineTest {
|
||||
("testTeardownDuringFormalRemovalProcess", testTeardownDuringFormalRemovalProcess),
|
||||
("testVariousChannelRemovalAPIsGoThroughRemovableChannelHandler", testVariousChannelRemovalAPIsGoThroughRemovableChannelHandler),
|
||||
("testNonRemovableChannelHandlerIsNotRemovable", testNonRemovableChannelHandlerIsNotRemovable),
|
||||
("testAddMultipleHandlers", testAddMultipleHandlers),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ class ChannelPipelineTest: XCTestCase {
|
||||
XCTAssertFalse(handler.handlerRemovedCalled.load())
|
||||
}
|
||||
do {
|
||||
try channel.pipeline.add(handler: handler).wait()
|
||||
try channel.pipeline.addHandler(handler).wait()
|
||||
XCTFail()
|
||||
} catch let err as ChannelError {
|
||||
XCTAssertEqual(err, .ioOnClosedChannel)
|
||||
@@ -101,12 +101,12 @@ class ChannelPipelineTest: XCTestCase {
|
||||
var buf = channel.allocator.buffer(capacity: 1024)
|
||||
buf.writeString("hello")
|
||||
|
||||
_ = try channel.pipeline.add(handler: TestChannelOutboundHandler<Int, ByteBuffer> { data in
|
||||
_ = try channel.pipeline.addHandler(TestChannelOutboundHandler<Int, ByteBuffer> { data in
|
||||
XCTAssertEqual(1, data)
|
||||
return buf
|
||||
}).wait()
|
||||
|
||||
_ = try channel.pipeline.add(handler: TestChannelOutboundHandler<String, Int> { data in
|
||||
_ = try channel.pipeline.addHandler(TestChannelOutboundHandler<String, Int> { data in
|
||||
XCTAssertEqual("msg", data)
|
||||
return 1
|
||||
}).wait()
|
||||
@@ -131,8 +131,8 @@ class ChannelPipelineTest: XCTestCase {
|
||||
ipv4SocketAddress.sin_port = (12345 as in_port_t).bigEndian
|
||||
let sa = SocketAddress(ipv4SocketAddress, host: "foobar.com")
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: NoBindAllowed()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: TestChannelOutboundHandler<ByteBuffer, ByteBuffer> { data in
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(NoBindAllowed()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(TestChannelOutboundHandler<ByteBuffer, ByteBuffer> { data in
|
||||
data
|
||||
}).wait())
|
||||
|
||||
@@ -184,8 +184,8 @@ class ChannelPipelineTest: XCTestCase {
|
||||
let channel = EmbeddedChannel()
|
||||
|
||||
let h = FireChannelReadOnRemoveHandler()
|
||||
_ = try channel.pipeline.add(handler: h).flatMap {
|
||||
channel.pipeline.remove(handler: h)
|
||||
_ = try channel.pipeline.addHandler(h).flatMap {
|
||||
channel.pipeline.removeHandler(h)
|
||||
}.wait()
|
||||
|
||||
XCTAssertEqual(Optional<Int>.some(1), channel.readInbound())
|
||||
@@ -287,13 +287,13 @@ class ChannelPipelineTest: XCTestCase {
|
||||
let loop = channel.eventLoop as! EmbeddedEventLoop
|
||||
loop.run()
|
||||
|
||||
try channel.pipeline.add(handler: PrintOutboundAsByteBufferHandler()).wait()
|
||||
try channel.pipeline.add(handler: MarkingInboundHandler(number: 2)).wait()
|
||||
try channel.pipeline.add(handler: WriteOnReadHandler()).wait()
|
||||
try channel.pipeline.add(handler: MarkingOutboundHandler(number: 4)).wait()
|
||||
try channel.pipeline.add(handler: WriteOnReadHandler()).wait()
|
||||
try channel.pipeline.add(handler: MarkingInboundHandler(number: 6)).wait()
|
||||
try channel.pipeline.add(handler: WriteOnReadHandler()).wait()
|
||||
try channel.pipeline.addHandler(PrintOutboundAsByteBufferHandler()).wait()
|
||||
try channel.pipeline.addHandler(MarkingInboundHandler(number: 2)).wait()
|
||||
try channel.pipeline.addHandler(WriteOnReadHandler()).wait()
|
||||
try channel.pipeline.addHandler(MarkingOutboundHandler(number: 4)).wait()
|
||||
try channel.pipeline.addHandler(WriteOnReadHandler()).wait()
|
||||
try channel.pipeline.addHandler(MarkingInboundHandler(number: 6)).wait()
|
||||
try channel.pipeline.addHandler(WriteOnReadHandler()).wait()
|
||||
|
||||
try channel.writeInbound([])
|
||||
loop.run()
|
||||
@@ -363,8 +363,8 @@ class ChannelPipelineTest: XCTestCase {
|
||||
weakHandlerContext2 = ctx
|
||||
}
|
||||
weakHandler2 = handler2
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: handler1).flatMap {
|
||||
channel.pipeline.add(handler: handler2)
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(handler1).flatMap {
|
||||
channel.pipeline.addHandler(handler2)
|
||||
}.wait())
|
||||
}()
|
||||
|
||||
@@ -373,7 +373,7 @@ class ChannelPipelineTest: XCTestCase {
|
||||
XCTAssertNotNil(weakHandlerContext1)
|
||||
XCTAssertNotNil(weakHandlerContext2)
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.remove(handler: weakHandler1!).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.removeHandler(weakHandler1!).wait())
|
||||
|
||||
XCTAssertNil(weakHandler1)
|
||||
XCTAssertNotNil(weakHandler2)
|
||||
@@ -435,13 +435,13 @@ class ChannelPipelineTest: XCTestCase {
|
||||
var buffer = channel.allocator.buffer(capacity: 12)
|
||||
buffer.writeStaticString("hello, world")
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: countHandler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(countHandler).wait())
|
||||
XCTAssertFalse(try channel.writeInbound(buffer))
|
||||
XCTAssertEqual(countHandler.intReadCount, 0)
|
||||
|
||||
try channel.pipeline.addHandlers(TransformByteBufferToStringHandler(),
|
||||
TransformStringToIntHandler(),
|
||||
first: true).wait()
|
||||
position: .first).wait()
|
||||
XCTAssertFalse(try channel.writeInbound(buffer))
|
||||
XCTAssertEqual(countHandler.intReadCount, 1)
|
||||
}
|
||||
@@ -453,9 +453,10 @@ class ChannelPipelineTest: XCTestCase {
|
||||
}
|
||||
|
||||
let firstHandler = IndexWritingHandler(1)
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: firstHandler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: IndexWritingHandler(2)).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: IndexWritingHandler(3), after: firstHandler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(firstHandler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(IndexWritingHandler(2)).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(IndexWritingHandler(3),
|
||||
position: .after(firstHandler)).wait())
|
||||
|
||||
channel.assertReadIndexOrder([1, 3, 2])
|
||||
channel.assertWriteIndexOrder([2, 3, 1])
|
||||
@@ -468,9 +469,10 @@ class ChannelPipelineTest: XCTestCase {
|
||||
}
|
||||
|
||||
let secondHandler = IndexWritingHandler(2)
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: IndexWritingHandler(1)).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: secondHandler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: IndexWritingHandler(3), before: secondHandler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(IndexWritingHandler(1)).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(secondHandler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(IndexWritingHandler(3),
|
||||
position: .before(secondHandler)).wait())
|
||||
|
||||
channel.assertReadIndexOrder([1, 3, 2])
|
||||
channel.assertWriteIndexOrder([2, 3, 1])
|
||||
@@ -483,9 +485,10 @@ class ChannelPipelineTest: XCTestCase {
|
||||
}
|
||||
|
||||
let secondHandler = IndexWritingHandler(2)
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: IndexWritingHandler(1)).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: secondHandler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: IndexWritingHandler(3), after: secondHandler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(IndexWritingHandler(1)).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(secondHandler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(IndexWritingHandler(3),
|
||||
position: .after(secondHandler)).wait())
|
||||
|
||||
channel.assertReadIndexOrder([1, 2, 3])
|
||||
channel.assertWriteIndexOrder([3, 2, 1])
|
||||
@@ -498,9 +501,10 @@ class ChannelPipelineTest: XCTestCase {
|
||||
}
|
||||
|
||||
let firstHandler = IndexWritingHandler(1)
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: firstHandler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: IndexWritingHandler(2)).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: IndexWritingHandler(3), before: firstHandler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(firstHandler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(IndexWritingHandler(2)).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(IndexWritingHandler(3),
|
||||
position: .before(firstHandler)).wait())
|
||||
|
||||
channel.assertReadIndexOrder([3, 1, 2])
|
||||
channel.assertWriteIndexOrder([2, 1, 3])
|
||||
@@ -520,12 +524,12 @@ class ChannelPipelineTest: XCTestCase {
|
||||
}
|
||||
|
||||
let handler = IndexWritingHandler(1)
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: handler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
|
||||
XCTAssertNoThrow(try channel.close().wait())
|
||||
(channel.eventLoop as! EmbeddedEventLoop).run()
|
||||
|
||||
do {
|
||||
try channel.pipeline.add(handler: IndexWritingHandler(2), after: handler).wait()
|
||||
try channel.pipeline.addHandler(IndexWritingHandler(2), position: .after(handler)).wait()
|
||||
XCTFail("Did not throw")
|
||||
} catch ChannelError.ioOnClosedChannel {
|
||||
// all good
|
||||
@@ -548,12 +552,12 @@ class ChannelPipelineTest: XCTestCase {
|
||||
}
|
||||
|
||||
let handler = IndexWritingHandler(1)
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: handler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
|
||||
XCTAssertNoThrow(try channel.close().wait())
|
||||
(channel.eventLoop as! EmbeddedEventLoop).run()
|
||||
|
||||
do {
|
||||
try channel.pipeline.add(handler: IndexWritingHandler(2), before: handler).wait()
|
||||
try channel.pipeline.addHandler(IndexWritingHandler(2), position: .before(handler)).wait()
|
||||
XCTFail("Did not throw")
|
||||
} catch ChannelError.ioOnClosedChannel {
|
||||
// all good
|
||||
@@ -585,8 +589,8 @@ class ChannelPipelineTest: XCTestCase {
|
||||
|
||||
let h1 = TypeAHandler()
|
||||
let h2 = TypeBHandler()
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: h1).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: h2).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(h1).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(h2).wait())
|
||||
|
||||
XCTAssertTrue(try h1 === channel.pipeline.context(handlerType: TypeAHandler.self).wait().handler)
|
||||
XCTAssertTrue(try h2 === channel.pipeline.context(handlerType: TypeBHandler.self).wait().handler)
|
||||
@@ -614,8 +618,8 @@ class ChannelPipelineTest: XCTestCase {
|
||||
|
||||
let h1 = TestHandler()
|
||||
let h2 = TestHandler()
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: h1).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: h2).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(h1).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(h2).wait())
|
||||
|
||||
XCTAssertTrue(try h1 === channel.pipeline.context(handlerType: TestHandler.self).wait().handler)
|
||||
XCTAssertFalse(try h2 === channel.pipeline.context(handlerType: TestHandler.self).wait().handler)
|
||||
@@ -665,14 +669,14 @@ class ChannelPipelineTest: XCTestCase {
|
||||
}
|
||||
|
||||
do {
|
||||
_ = try channel.pipeline.remove(name: HeadChannelHandler.name).wait()
|
||||
_ = try channel.pipeline.removeHandler(name: HeadChannelHandler.name).wait()
|
||||
XCTFail()
|
||||
} catch let err as ChannelPipelineError where err == .notFound {
|
||||
/// expected
|
||||
}
|
||||
|
||||
do {
|
||||
_ = try channel.pipeline.remove(name: TailChannelHandler.name).wait()
|
||||
_ = try channel.pipeline.removeHandler(name: TailChannelHandler.name).wait()
|
||||
XCTFail()
|
||||
} catch let err as ChannelPipelineError where err == .notFound {
|
||||
/// expected
|
||||
@@ -691,7 +695,7 @@ class ChannelPipelineTest: XCTestCase {
|
||||
_ = try? channel.finish()
|
||||
}
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: NoOpHandler()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(NoOpHandler()).wait())
|
||||
|
||||
let context = try assertNoThrowWithValue(channel.pipeline.context(handlerType: NoOpHandler.self).wait())
|
||||
|
||||
@@ -706,7 +710,7 @@ class ChannelPipelineTest: XCTestCase {
|
||||
|
||||
XCTAssertNil(channel.readOutbound())
|
||||
XCTAssertNoThrow(try channel.throwIfErrorCaught())
|
||||
channel.pipeline.remove(ctx: context, promise: removalPromise)
|
||||
channel.pipeline.removeHandler(ctx: context, promise: removalPromise)
|
||||
|
||||
XCTAssertNoThrow(try removalPromise.futureResult.wait())
|
||||
guard case .some(.byteBuffer(let receivedBuffer)) = channel.readOutbound(as: IOData.self) else {
|
||||
@@ -737,7 +741,7 @@ class ChannelPipelineTest: XCTestCase {
|
||||
XCTAssertFalse(try channel.finish())
|
||||
}
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: NoOpHandler()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(NoOpHandler()).wait())
|
||||
|
||||
let context = try assertNoThrowWithValue(channel.pipeline.context(handlerType: NoOpHandler.self).wait())
|
||||
|
||||
@@ -746,7 +750,7 @@ class ChannelPipelineTest: XCTestCase {
|
||||
|
||||
XCTAssertNil(channel.readOutbound())
|
||||
XCTAssertNoThrow(try channel.throwIfErrorCaught())
|
||||
channel.pipeline.remove(ctx: context).whenSuccess {
|
||||
channel.pipeline.removeHandler(ctx: context).whenSuccess {
|
||||
context.writeAndFlush(NIOAny(buffer), promise: nil)
|
||||
context.fireErrorCaught(DummyError())
|
||||
}
|
||||
@@ -766,7 +770,7 @@ class ChannelPipelineTest: XCTestCase {
|
||||
_ = try? channel.finish()
|
||||
}
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.add(name: "TestHandler", handler: NoOpHandler()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(NoOpHandler(), name: "TestHandler").wait())
|
||||
|
||||
let context = try assertNoThrowWithValue(channel.pipeline.context(handlerType: NoOpHandler.self).wait())
|
||||
|
||||
@@ -783,7 +787,7 @@ class ChannelPipelineTest: XCTestCase {
|
||||
|
||||
XCTAssertNil(channel.readOutbound())
|
||||
XCTAssertNoThrow(try channel.throwIfErrorCaught())
|
||||
channel.pipeline.remove(name: "TestHandler", promise: removalPromise)
|
||||
channel.pipeline.removeHandler(name: "TestHandler", promise: removalPromise)
|
||||
|
||||
XCTAssertEqual(channel.readOutbound(), buffer)
|
||||
|
||||
@@ -809,7 +813,7 @@ class ChannelPipelineTest: XCTestCase {
|
||||
XCTAssertFalse(try channel.finish())
|
||||
}
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.add(name: "TestHandler", handler: NoOpHandler()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(NoOpHandler(), name: "TestHandler").wait())
|
||||
|
||||
let context = try assertNoThrowWithValue(channel.pipeline.context(handlerType: NoOpHandler.self).wait())
|
||||
|
||||
@@ -818,7 +822,7 @@ class ChannelPipelineTest: XCTestCase {
|
||||
|
||||
XCTAssertNil(channel.readOutbound())
|
||||
XCTAssertNoThrow(try channel.throwIfErrorCaught())
|
||||
channel.pipeline.remove(name: "TestHandler").whenSuccess {
|
||||
channel.pipeline.removeHandler(name: "TestHandler").whenSuccess {
|
||||
context.writeAndFlush(NIOAny(buffer), promise: nil)
|
||||
context.fireErrorCaught(DummyError())
|
||||
}
|
||||
@@ -839,7 +843,7 @@ class ChannelPipelineTest: XCTestCase {
|
||||
}
|
||||
|
||||
let handler = NoOpHandler()
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: handler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
|
||||
|
||||
let context = try assertNoThrowWithValue(channel.pipeline.context(handlerType: NoOpHandler.self).wait())
|
||||
|
||||
@@ -854,7 +858,7 @@ class ChannelPipelineTest: XCTestCase {
|
||||
|
||||
XCTAssertNil(channel.readOutbound())
|
||||
XCTAssertNoThrow(try channel.throwIfErrorCaught())
|
||||
channel.pipeline.remove(handler: handler, promise: removalPromise)
|
||||
channel.pipeline.removeHandler(handler, promise: removalPromise)
|
||||
|
||||
XCTAssertEqual(channel.readOutbound(), buffer)
|
||||
|
||||
@@ -881,7 +885,7 @@ class ChannelPipelineTest: XCTestCase {
|
||||
}
|
||||
|
||||
let handler = NoOpHandler()
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: handler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
|
||||
|
||||
let context = try assertNoThrowWithValue(channel.pipeline.context(handlerType: NoOpHandler.self).wait())
|
||||
|
||||
@@ -890,7 +894,7 @@ class ChannelPipelineTest: XCTestCase {
|
||||
|
||||
XCTAssertNil(channel.readOutbound())
|
||||
XCTAssertNoThrow(try channel.throwIfErrorCaught())
|
||||
channel.pipeline.remove(handler: handler).whenSuccess {
|
||||
channel.pipeline.removeHandler(handler).whenSuccess {
|
||||
context.writeAndFlush(NIOAny(buffer), promise: nil)
|
||||
context.fireErrorCaught(DummyError())
|
||||
}
|
||||
@@ -918,7 +922,7 @@ class ChannelPipelineTest: XCTestCase {
|
||||
}
|
||||
let client = try assertNoThrowWithValue(ClientBootstrap(group: group)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.add(handler: handler)
|
||||
channel.pipeline.addHandler(handler)
|
||||
}
|
||||
.connect(to: server.localAddress!)
|
||||
.wait())
|
||||
@@ -960,7 +964,7 @@ class ChannelPipelineTest: XCTestCase {
|
||||
|
||||
// let's trigger the removal process
|
||||
XCTAssertNoThrow(try channel.pipeline.context(handlerType: NeverCompleteRemovalHandler.self).map { handler in
|
||||
channel.pipeline.remove(ctx: handler, promise: nil)
|
||||
channel.pipeline.removeHandler(ctx: handler, promise: nil)
|
||||
}.wait())
|
||||
|
||||
XCTAssertNoThrow(try removalTokenPromise.futureResult.map { removalToken in
|
||||
@@ -999,15 +1003,15 @@ class ChannelPipelineTest: XCTestCase {
|
||||
|
||||
let channel = EmbeddedChannel()
|
||||
let allHandlers = [Handler(), Handler(), Handler()]
|
||||
XCTAssertNoThrow(try channel.pipeline.add(name: "the first one to remove", handler: allHandlers[0]).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: allHandlers[1]).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(name: "the last one to remove", handler: allHandlers[2]).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(allHandlers[0], name: "the first one to remove").wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(allHandlers[1]).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(allHandlers[2], name: "the last one to remove").wait())
|
||||
|
||||
let lastContext = try! channel.pipeline.context(name: "the last one to remove").wait()
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.remove(name: "the first one to remove").wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.remove(handler: allHandlers[1]).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.remove(ctx: lastContext).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.removeHandler(name: "the first one to remove").wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.removeHandler(allHandlers[1]).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.removeHandler(ctx: lastContext).wait())
|
||||
|
||||
allHandlers.forEach {
|
||||
XCTAssertTrue($0.removeHandlerCalled)
|
||||
@@ -1022,19 +1026,19 @@ class ChannelPipelineTest: XCTestCase {
|
||||
|
||||
let channel = EmbeddedChannel()
|
||||
let allHandlers = [NonRemovableHandler(), NonRemovableHandler(), NonRemovableHandler()]
|
||||
XCTAssertNoThrow(try channel.pipeline.add(name: "1", handler: allHandlers[0]).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(name: "2", handler: allHandlers[1]).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(allHandlers[0], name: "1").wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(allHandlers[1], name: "2").wait())
|
||||
|
||||
let lastContext = try! channel.pipeline.context(name: "1").wait()
|
||||
|
||||
XCTAssertThrowsError(try channel.pipeline.remove(name: "2").wait()) { error in
|
||||
XCTAssertThrowsError(try channel.pipeline.removeHandler(name: "2").wait()) { error in
|
||||
if let error = error as? ChannelError {
|
||||
XCTAssertEqual(ChannelError.unremovableHandler, error)
|
||||
} else {
|
||||
XCTFail("unexpected error: \(error)")
|
||||
}
|
||||
}
|
||||
XCTAssertThrowsError(try channel.pipeline.remove(ctx: lastContext).wait()) { error in
|
||||
XCTAssertThrowsError(try channel.pipeline.removeHandler(ctx: lastContext).wait()) { error in
|
||||
if let error = error as? ChannelError {
|
||||
XCTAssertEqual(ChannelError.unremovableHandler, error)
|
||||
} else {
|
||||
@@ -1042,4 +1046,51 @@ class ChannelPipelineTest: XCTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testAddMultipleHandlers() {
|
||||
typealias Handler = TestAddMultipleHandlersHandlerWorkingAroundSR9956
|
||||
let channel = EmbeddedChannel()
|
||||
let a = Handler()
|
||||
let b = Handler()
|
||||
let c = Handler()
|
||||
let d = Handler()
|
||||
let e = Handler()
|
||||
let f = Handler()
|
||||
let g = Handler()
|
||||
let h = Handler()
|
||||
let i = Handler()
|
||||
let j = Handler()
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(c).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(h).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandlers([d, e], position: .after(c)).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandlers([f, g], position: .before(h)).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandlers([a, b], position: .first).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandlers([i, j], position: .last).wait())
|
||||
|
||||
Handler.allHandlers = []
|
||||
channel.pipeline.fireUserInboundEventTriggered(())
|
||||
|
||||
XCTAssertEqual([a, b, c, d, e, f, g, h, i, j], Handler.allHandlers)
|
||||
}
|
||||
}
|
||||
|
||||
// this should be within `testAddMultipleHandlers` but https://bugs.swift.org/browse/SR-9956
|
||||
final class TestAddMultipleHandlersHandlerWorkingAroundSR9956: ChannelDuplexHandler, Equatable {
|
||||
typealias InboundIn = Never
|
||||
typealias OutboundIn = Never
|
||||
|
||||
static var allHandlers: [TestAddMultipleHandlersHandlerWorkingAroundSR9956] = []
|
||||
|
||||
init() {}
|
||||
|
||||
func userInboundEventTriggered(ctx: ChannelHandlerContext, event: Any) {
|
||||
TestAddMultipleHandlersHandlerWorkingAroundSR9956.allHandlers.append(self)
|
||||
ctx.fireUserInboundEventTriggered(event)
|
||||
}
|
||||
|
||||
public static func == (lhs: TestAddMultipleHandlersHandlerWorkingAroundSR9956,
|
||||
rhs: TestAddMultipleHandlersHandlerWorkingAroundSR9956) -> Bool {
|
||||
return lhs === rhs
|
||||
}
|
||||
}
|
||||
@@ -82,12 +82,12 @@ public class ChannelTests: XCTestCase {
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelInitializer { channel in
|
||||
serverAcceptedChannelPromise.succeed(channel)
|
||||
return channel.pipeline.add(handler: serverLifecycleHandler)
|
||||
return channel.pipeline.addHandler(serverLifecycleHandler)
|
||||
}.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
let clientLifecycleHandler = ChannelLifecycleHandler()
|
||||
let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group)
|
||||
.channelInitializer({ (channel: Channel) in channel.pipeline.add(handler: clientLifecycleHandler) })
|
||||
.channelInitializer({ (channel: Channel) in channel.pipeline.addHandler(clientLifecycleHandler) })
|
||||
.connect(to: serverChannel.localAddress!).wait())
|
||||
|
||||
var buffer = clientChannel.allocator.buffer(capacity: 1)
|
||||
@@ -1118,8 +1118,8 @@ public class ChannelTests: XCTestCase {
|
||||
let verificationHandler = ShutdownVerificationHandler(shutdownEvent: .output, promise: group.next().makePromise())
|
||||
let future = ClientBootstrap(group: group)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.add(handler: verificationHandler).flatMap {
|
||||
channel.pipeline.add(handler: byteCountingHandler)
|
||||
channel.pipeline.addHandler(verificationHandler).flatMap {
|
||||
channel.pipeline.addHandler(byteCountingHandler)
|
||||
}
|
||||
}
|
||||
.connect(to: try! server.localAddress())
|
||||
@@ -1181,8 +1181,8 @@ public class ChannelTests: XCTestCase {
|
||||
let verificationHandler = ShutdownVerificationHandler(shutdownEvent: .input, promise: group.next().makePromise())
|
||||
let future = ClientBootstrap(group: group)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.add(handler: VerifyNoReadHandler()).flatMap {
|
||||
channel.pipeline.add(handler: verificationHandler)
|
||||
channel.pipeline.addHandler(VerifyNoReadHandler()).flatMap {
|
||||
channel.pipeline.addHandler(verificationHandler)
|
||||
}
|
||||
}
|
||||
.channelOption(ChannelOptions.allowRemoteHalfClosure, value: true)
|
||||
@@ -1237,7 +1237,7 @@ public class ChannelTests: XCTestCase {
|
||||
|
||||
let future = ClientBootstrap(group: group)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.add(handler: verificationHandler)
|
||||
channel.pipeline.addHandler(verificationHandler)
|
||||
}
|
||||
.channelOption(ChannelOptions.allowRemoteHalfClosure, value: true)
|
||||
.connect(to: try! server.localAddress())
|
||||
@@ -1385,7 +1385,7 @@ public class ChannelTests: XCTestCase {
|
||||
|
||||
let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group)
|
||||
.channelInitializer {
|
||||
$0.pipeline.add(handler: StuffHandler(promise: promise))
|
||||
$0.pipeline.addHandler(StuffHandler(promise: promise))
|
||||
}
|
||||
.connect(to: serverChannel.localAddress!).wait())
|
||||
weakClientChannel = clientChannel
|
||||
@@ -1477,7 +1477,7 @@ public class ChannelTests: XCTestCase {
|
||||
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelInitializer { ch in
|
||||
ch.pipeline.add(handler: AddressVerificationHandler())
|
||||
ch.pipeline.addHandler(AddressVerificationHandler())
|
||||
}
|
||||
.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
@@ -1541,7 +1541,7 @@ public class ChannelTests: XCTestCase {
|
||||
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelInitializer {
|
||||
$0.pipeline.add(handler: readDelayer)
|
||||
$0.pipeline.addHandler(readDelayer)
|
||||
}
|
||||
.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
@@ -1598,7 +1598,7 @@ public class ChannelTests: XCTestCase {
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelOption(ChannelOptions.autoRead, value: false)
|
||||
.childChannelInitializer { ch in
|
||||
ch.pipeline.add(handler: handler)
|
||||
ch.pipeline.addHandler(handler)
|
||||
}
|
||||
.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
@@ -1654,7 +1654,7 @@ public class ChannelTests: XCTestCase {
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelOption(ChannelOptions.autoRead, value: false)
|
||||
.childChannelInitializer { ch in
|
||||
ch.pipeline.add(handler: VerifyEOFReadOrderingAndCloseInChannelReadHandler())
|
||||
ch.pipeline.addHandler(VerifyEOFReadOrderingAndCloseInChannelReadHandler())
|
||||
}
|
||||
.childChannelOption(ChannelOptions.maxMessagesPerRead, value: 1)
|
||||
.childChannelOption(ChannelOptions.recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: 8))
|
||||
@@ -1705,7 +1705,7 @@ public class ChannelTests: XCTestCase {
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelOption(ChannelOptions.autoRead, value: false)
|
||||
.childChannelInitializer { ch in
|
||||
ch.pipeline.add(handler: CloseWhenWeGetEOFHandler(allDone: allDone))
|
||||
ch.pipeline.addHandler(CloseWhenWeGetEOFHandler(allDone: allDone))
|
||||
}
|
||||
// maxMessagesPerRead is large so that we definitely spin and seen the EOF
|
||||
.childChannelOption(ChannelOptions.maxMessagesPerRead, value: 10)
|
||||
@@ -1756,7 +1756,7 @@ public class ChannelTests: XCTestCase {
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelOption(ChannelOptions.autoRead, value: false)
|
||||
.childChannelInitializer { ch in
|
||||
ch.pipeline.add(handler: ChannelInactiveVerificationHandler(promise))
|
||||
ch.pipeline.addHandler(ChannelInactiveVerificationHandler(promise))
|
||||
}
|
||||
.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
@@ -1844,7 +1844,7 @@ public class ChannelTests: XCTestCase {
|
||||
let collector = ChannelCollector(group: group)
|
||||
let serverBoot = ServerBootstrap(group: group)
|
||||
.childChannelInitializer { channel in
|
||||
return channel.pipeline.add(handler: CheckActiveHandler(channelCollector: collector))
|
||||
return channel.pipeline.addHandler(CheckActiveHandler(channelCollector: collector))
|
||||
}
|
||||
let listeningChannel = try serverBoot.bind(host: "127.0.0.1", port: 0).wait()
|
||||
let clientBoot = ClientBootstrap(group: group)
|
||||
@@ -1951,7 +1951,7 @@ public class ChannelTests: XCTestCase {
|
||||
|
||||
let bootstrap = try assertNoThrowWithValue(ServerBootstrap(group: serverEL)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: WriteImmediatelyHandler(writeDonePromise: serverWriteHappenedPromise))
|
||||
channel.pipeline.addHandler(WriteImmediatelyHandler(writeDonePromise: serverWriteHappenedPromise))
|
||||
}
|
||||
.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
@@ -1962,7 +1962,7 @@ public class ChannelTests: XCTestCase {
|
||||
// again which our special `Socket` subclass will let succeed.
|
||||
_ = try sc.selectable.connect(to: bootstrap.localAddress!)
|
||||
try serverWriteHappenedPromise.futureResult.wait()
|
||||
try sc.pipeline.add(handler: ReadDoesNotHappen(hasRegisteredPromise: clientHasRegistered,
|
||||
try sc.pipeline.addHandler(ReadDoesNotHappen(hasRegisteredPromise: clientHasRegistered,
|
||||
hasUnregisteredPromise: clientHasUnregistered,
|
||||
hasReadPromise: clientHasRead)).flatMap {
|
||||
// this will succeed and should not cause the socket to be read even though there'll be something
|
||||
@@ -2133,7 +2133,7 @@ public class ChannelTests: XCTestCase {
|
||||
// `register` will succeed.
|
||||
|
||||
sc.register().flatMap {
|
||||
sc.pipeline.add(handler: VerifyThingsAreRightHandler(allDone: allDone))
|
||||
sc.pipeline.addHandler(VerifyThingsAreRightHandler(allDone: allDone))
|
||||
}.flatMap {
|
||||
sc.connect(to: serverChannel.localAddress!)
|
||||
}
|
||||
@@ -2175,7 +2175,7 @@ public class ChannelTests: XCTestCase {
|
||||
|
||||
let allDone = group.next().makePromise(of: Void.self)
|
||||
let cf = try! sc.eventLoop.submit {
|
||||
sc.pipeline.add(handler: VerifyConnectionFailureHandler(allDone: allDone)).flatMap {
|
||||
sc.pipeline.addHandler(VerifyConnectionFailureHandler(allDone: allDone)).flatMap {
|
||||
sc.register().flatMap {
|
||||
sc.connect(to: serverChannel.localAddress!)
|
||||
}
|
||||
@@ -2221,7 +2221,7 @@ public class ChannelTests: XCTestCase {
|
||||
|
||||
let allDone = group.next().makePromise(of: Void.self)
|
||||
try! sc.eventLoop.submit {
|
||||
let f = sc.pipeline.add(handler: VerifyConnectionFailureHandler(allDone: allDone)).flatMap {
|
||||
let f = sc.pipeline.addHandler(VerifyConnectionFailureHandler(allDone: allDone)).flatMap {
|
||||
sc.register().flatMap {
|
||||
sc.connect(to: serverChannel.localAddress!)
|
||||
}
|
||||
@@ -2378,7 +2378,7 @@ public class ChannelTests: XCTestCase {
|
||||
do {
|
||||
let clientChannel = try ClientBootstrap(group: group)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.add(handler: FailRegistrationAndDelayCloseHandler())
|
||||
channel.pipeline.addHandler(FailRegistrationAndDelayCloseHandler())
|
||||
}
|
||||
.connect(to: serverChannel.localAddress!)
|
||||
.wait()
|
||||
@@ -2397,7 +2397,7 @@ public class ChannelTests: XCTestCase {
|
||||
}
|
||||
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: FailRegistrationAndDelayCloseHandler())
|
||||
channel.pipeline.addHandler(FailRegistrationAndDelayCloseHandler())
|
||||
}
|
||||
.bind(host: "localhost", port: 0).wait())
|
||||
defer {
|
||||
@@ -2417,7 +2417,7 @@ public class ChannelTests: XCTestCase {
|
||||
do {
|
||||
let serverChannel = try ServerBootstrap(group: group)
|
||||
.serverChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: FailRegistrationAndDelayCloseHandler())
|
||||
channel.pipeline.addHandler(FailRegistrationAndDelayCloseHandler())
|
||||
}
|
||||
.bind(host: "localhost", port: 0).wait()
|
||||
XCTFail("shouldn't be reached")
|
||||
@@ -2573,7 +2573,7 @@ public class ChannelTests: XCTestCase {
|
||||
let server = try assertNoThrowWithValue(ServerBootstrap(group: singleThreadedELG)
|
||||
.childChannelOption(ChannelOptions.allowRemoteHalfClosure, value: true)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: WriteWhenActiveHandler(channelAvailablePromise: serverChannelAvailablePromise))
|
||||
channel.pipeline.addHandler(WriteWhenActiveHandler(channelAvailablePromise: serverChannelAvailablePromise))
|
||||
}
|
||||
.bind(host: "127.0.0.1", port: 0)
|
||||
.wait())
|
||||
@@ -2586,7 +2586,7 @@ public class ChannelTests: XCTestCase {
|
||||
eventLoop: singleThreadedELG.next() as! SelectableEventLoop))
|
||||
XCTAssertNoThrow(try c.setOption(ChannelOptions.autoRead, value: false).wait())
|
||||
XCTAssertNoThrow(try c.setOption(ChannelOptions.allowRemoteHalfClosure, value: true).wait())
|
||||
XCTAssertNoThrow(try c.pipeline.add(handler: MakeChannelInactiveInReadCausedByWriteErrorHandler(serverChannel: serverChannelAvailablePromise.futureResult,
|
||||
XCTAssertNoThrow(try c.pipeline.addHandler(MakeChannelInactiveInReadCausedByWriteErrorHandler(serverChannel: serverChannelAvailablePromise.futureResult,
|
||||
allDonePromise: allDonePromise)).wait())
|
||||
XCTAssertNoThrow(try c.register().wait())
|
||||
XCTAssertNoThrow(try c.connect(to: server.localAddress!).wait())
|
||||
|
||||
@@ -106,7 +106,7 @@ public class ByteToMessageDecoderTest: XCTestCase {
|
||||
func testDecoder() throws {
|
||||
let channel = EmbeddedChannel()
|
||||
|
||||
_ = try channel.pipeline.add(handler: ByteToMessageHandler(ByteToInt32Decoder())).wait()
|
||||
_ = try channel.pipeline.addHandler(ByteToMessageHandler(ByteToInt32Decoder())).wait()
|
||||
|
||||
var buffer = channel.allocator.buffer(capacity: 32)
|
||||
buffer.writeInteger(Int32(1))
|
||||
@@ -137,8 +137,8 @@ public class ByteToMessageDecoderTest: XCTestCase {
|
||||
XCTAssertNoThrow(try channel.finish())
|
||||
}
|
||||
let inactivePromiser = ChannelInactivePromiser(channel: channel)
|
||||
_ = try channel.pipeline.add(handler: ByteToMessageHandler(ByteToInt32Decoder())).wait()
|
||||
_ = try channel.pipeline.add(handler: inactivePromiser).wait()
|
||||
_ = try channel.pipeline.addHandler(ByteToMessageHandler(ByteToInt32Decoder())).wait()
|
||||
_ = try channel.pipeline.addHandler(inactivePromiser).wait()
|
||||
|
||||
var buffer = channel.allocator.buffer(capacity: 32)
|
||||
buffer.writeInteger(Int32(1))
|
||||
@@ -159,7 +159,7 @@ public class ByteToMessageDecoderTest: XCTestCase {
|
||||
|
||||
XCTAssertEqual(testDecoderIsNotQuadratic_mallocs, 0)
|
||||
XCTAssertEqual(testDecoderIsNotQuadratic_reallocs, 0)
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: ByteToMessageHandler(ForeverDecoder())).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(ByteToMessageHandler(ForeverDecoder())).wait())
|
||||
|
||||
let dummyAllocator = ByteBufferAllocator(hookedMalloc: testDecoderIsNotQuadratic_mallocHook,
|
||||
hookedRealloc: testDecoderIsNotQuadratic_reallocHook,
|
||||
@@ -186,7 +186,7 @@ public class ByteToMessageDecoderTest: XCTestCase {
|
||||
}
|
||||
|
||||
let decoder = ByteToMessageHandler(LargeChunkDecoder())
|
||||
_ = try channel.pipeline.add(handler: decoder).wait()
|
||||
_ = try channel.pipeline.addHandler(decoder).wait()
|
||||
|
||||
// We're going to send in 513 bytes. This will cause a chunk to be passed on, and will leave
|
||||
// a 512-byte empty region in a 513 byte buffer. This will not cause a shrink.
|
||||
@@ -212,7 +212,7 @@ public class ByteToMessageDecoderTest: XCTestCase {
|
||||
}
|
||||
|
||||
let decoder = ByteToMessageHandler(OnceDecoder())
|
||||
_ = try channel.pipeline.add(handler: decoder).wait()
|
||||
_ = try channel.pipeline.addHandler(decoder).wait()
|
||||
|
||||
// We're going to send in 5119 bytes. This will be held.
|
||||
var buffer = channel.allocator.buffer(capacity: 5119)
|
||||
@@ -266,7 +266,7 @@ public class ByteToMessageDecoderTest: XCTestCase {
|
||||
|
||||
let testDecoder = TestDecoder()
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: ByteToMessageHandler(testDecoder)).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(ByteToMessageHandler(testDecoder)).wait())
|
||||
|
||||
var inputBuffer = channel.allocator.buffer(capacity: 4)
|
||||
/* 1 */
|
||||
@@ -392,7 +392,7 @@ public class ByteToMessageDecoderTest: XCTestCase {
|
||||
XCTAssertNoThrow(try channel.writeInbound(buffer))
|
||||
|
||||
channel.pipeline.context(handlerType: ByteToMessageHandler<PairOfBytesDecoder>.self).flatMap { ctx in
|
||||
return channel.pipeline.remove(ctx: ctx)
|
||||
return channel.pipeline.removeHandler(ctx: ctx)
|
||||
}.whenFailure { error in
|
||||
XCTFail("unexpected error: \(error)")
|
||||
}
|
||||
@@ -529,7 +529,7 @@ public class ByteToMessageDecoderTest: XCTestCase {
|
||||
mutating func decode(ctx: ChannelHandlerContext, buffer: inout ByteBuffer) throws -> DecodingState {
|
||||
if let slice = buffer.readSlice(length: 16) {
|
||||
ctx.fireChannelRead(self.wrapInboundOut(slice))
|
||||
ctx.pipeline.remove(ctx: ctx).whenFailure { error in
|
||||
ctx.pipeline.removeHandler(ctx: ctx).whenFailure { error in
|
||||
XCTFail("unexpected error: \(error)")
|
||||
}
|
||||
return .continue
|
||||
@@ -582,7 +582,7 @@ public class ByteToMessageDecoderTest: XCTestCase {
|
||||
}
|
||||
}
|
||||
let channel = EmbeddedChannel(handler: ByteToMessageHandler(Take16BytesThenCloseAndPassOnDecoder()))
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: DoNotForwardChannelInactiveHandler(), first: true).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(DoNotForwardChannelInactiveHandler(), position: .first).wait())
|
||||
var buffer = channel.allocator.buffer(capacity: 16)
|
||||
buffer.writeStaticString("0123456789abcdefQWER")
|
||||
XCTAssertNoThrow(try channel.writeInbound(buffer))
|
||||
@@ -605,7 +605,7 @@ public class ByteToMessageDecoderTest: XCTestCase {
|
||||
XCTAssertEqual(1, self.callsToDecode)
|
||||
ctx.fireChannelRead(self.wrapInboundOut(String(decoding: buffer.readBytes(length: 1)!,
|
||||
as: Unicode.UTF8.self)))
|
||||
ctx.pipeline.remove(ctx: ctx).whenFailure { error in
|
||||
ctx.pipeline.removeHandler(ctx: ctx).whenFailure { error in
|
||||
XCTFail("unexpected error: \(error)")
|
||||
}
|
||||
return .continue
|
||||
@@ -678,7 +678,7 @@ public class MessageToByteEncoderTest: XCTestCase {
|
||||
private func testEncoder(_ handler: ChannelHandler) throws {
|
||||
let channel = EmbeddedChannel()
|
||||
|
||||
_ = try channel.pipeline.add(handler: Int32ToByteEncoder()).wait()
|
||||
_ = try channel.pipeline.addHandler(Int32ToByteEncoder()).wait()
|
||||
|
||||
_ = try channel.writeAndFlush(NIOAny(Int32(5))).wait()
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ final class DatagramChannelTests: XCTestCase {
|
||||
return try DatagramBootstrap(group: group)
|
||||
.channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.add(name: "ByteReadRecorder", handler: DatagramReadRecorder<ByteBuffer>())
|
||||
channel.pipeline.addHandler(DatagramReadRecorder<ByteBuffer>(), name: "ByteReadRecorder")
|
||||
}
|
||||
.bind(host: "127.0.0.1", port: 0)
|
||||
.wait()
|
||||
@@ -405,7 +405,7 @@ final class DatagramChannelTests: XCTestCase {
|
||||
let channel = try DatagramChannel(socket: socket, eventLoop: group.next() as! SelectableEventLoop)
|
||||
let promise = channel.eventLoop.makePromise(of: IOError.self)
|
||||
XCTAssertNoThrow(try channel.register().wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: RecvFromHandler(promise)).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(RecvFromHandler(promise)).wait())
|
||||
XCTAssertNoThrow(try channel.bind(to: SocketAddress.init(ipAddress: "127.0.0.1", port: 0)).wait())
|
||||
|
||||
XCTAssertEqual(active, try channel.eventLoop.submit {
|
||||
|
||||
@@ -30,7 +30,7 @@ class EchoServerClientTest : XCTestCase {
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: countingHandler)
|
||||
channel.pipeline.addHandler(countingHandler)
|
||||
}.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
defer {
|
||||
@@ -65,7 +65,7 @@ class EchoServerClientTest : XCTestCase {
|
||||
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: WriteALotHandler())
|
||||
channel.pipeline.addHandler(WriteALotHandler())
|
||||
}.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
defer {
|
||||
@@ -75,8 +75,8 @@ class EchoServerClientTest : XCTestCase {
|
||||
let promise = group.next().makePromise(of: ByteBuffer.self)
|
||||
let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.add(handler: WriteOnConnectHandler(toWrite: "X")).flatMap { v2 in
|
||||
channel.pipeline.add(handler: ByteCountingHandler(numBytes: 10000, promise: promise))
|
||||
channel.pipeline.addHandler(WriteOnConnectHandler(toWrite: "X")).flatMap { v2 in
|
||||
channel.pipeline.addHandler(ByteCountingHandler(numBytes: 10000, promise: promise))
|
||||
}
|
||||
}
|
||||
.connect(to: serverChannel.localAddress!).wait())
|
||||
@@ -108,7 +108,7 @@ class EchoServerClientTest : XCTestCase {
|
||||
// Set the handlers that are appled to the accepted Channels
|
||||
.childChannelInitializer { channel in
|
||||
// Ensure we don't read faster then we can write by adding the BackPressureHandler into the pipeline.
|
||||
channel.pipeline.add(handler: countingHandler)
|
||||
channel.pipeline.addHandler(countingHandler)
|
||||
}.bind(unixDomainSocketPath: udsTempDir + "/server.sock").wait())
|
||||
|
||||
defer {
|
||||
@@ -152,7 +152,7 @@ class EchoServerClientTest : XCTestCase {
|
||||
|
||||
// Set the handlers that are appled to the accepted Channels
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: countingHandler)
|
||||
channel.pipeline.addHandler(countingHandler)
|
||||
}.bind(unixDomainSocketPath: udsTempDir + "/server.sock").wait())
|
||||
|
||||
defer {
|
||||
@@ -194,7 +194,7 @@ class EchoServerClientTest : XCTestCase {
|
||||
}
|
||||
|
||||
let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group)
|
||||
.channelInitializer { $0.pipeline.add(handler: handler) }
|
||||
.channelInitializer { $0.pipeline.addHandler(handler) }
|
||||
.connect(to: serverChannel.localAddress!).wait())
|
||||
|
||||
defer {
|
||||
@@ -213,7 +213,7 @@ class EchoServerClientTest : XCTestCase {
|
||||
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: EchoServer())
|
||||
channel.pipeline.addHandler(EchoServer())
|
||||
}.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
defer {
|
||||
@@ -223,7 +223,7 @@ class EchoServerClientTest : XCTestCase {
|
||||
let numBytes = 16 * 1024
|
||||
let countingHandler = ByteCountingHandler(numBytes: numBytes, promise: group.next().makePromise())
|
||||
let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group)
|
||||
.channelInitializer { $0.pipeline.add(handler: countingHandler) }
|
||||
.channelInitializer { $0.pipeline.addHandler(countingHandler) }
|
||||
.connect(to: serverChannel.localAddress!).wait())
|
||||
|
||||
defer {
|
||||
@@ -410,7 +410,7 @@ class EchoServerClientTest : XCTestCase {
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: handler)
|
||||
channel.pipeline.addHandler(handler)
|
||||
}.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
defer {
|
||||
@@ -445,10 +445,10 @@ class EchoServerClientTest : XCTestCase {
|
||||
.childChannelInitializer { channel in
|
||||
// When we've received all the bytes we know the connection is up. Remove the handler.
|
||||
_ = bytesReceivedPromise.futureResult.flatMap { (_: ByteBuffer) in
|
||||
channel.pipeline.remove(handler: byteCountingHandler)
|
||||
channel.pipeline.removeHandler(byteCountingHandler)
|
||||
}
|
||||
|
||||
return channel.pipeline.add(handler: byteCountingHandler)
|
||||
return channel.pipeline.addHandler(byteCountingHandler)
|
||||
}.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
defer {
|
||||
@@ -487,7 +487,7 @@ class EchoServerClientTest : XCTestCase {
|
||||
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: EchoServer())
|
||||
channel.pipeline.addHandler(EchoServer())
|
||||
}.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
defer {
|
||||
@@ -498,8 +498,8 @@ class EchoServerClientTest : XCTestCase {
|
||||
let promise = group.next().makePromise(of: ByteBuffer.self)
|
||||
let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.add(handler: WriteOnConnectHandler(toWrite: stringToWrite)).flatMap {
|
||||
channel.pipeline.add(handler: ByteCountingHandler(numBytes: stringToWrite.utf8.count, promise: promise))
|
||||
channel.pipeline.addHandler(WriteOnConnectHandler(toWrite: stringToWrite)).flatMap {
|
||||
channel.pipeline.addHandler(ByteCountingHandler(numBytes: stringToWrite.utf8.count, promise: promise))
|
||||
}
|
||||
}
|
||||
.connect(to: serverChannel.localAddress!).wait())
|
||||
@@ -521,7 +521,7 @@ class EchoServerClientTest : XCTestCase {
|
||||
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: WriteOnConnectHandler(toWrite: stringToWrite))
|
||||
channel.pipeline.addHandler(WriteOnConnectHandler(toWrite: stringToWrite))
|
||||
}.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
defer {
|
||||
@@ -531,7 +531,7 @@ class EchoServerClientTest : XCTestCase {
|
||||
let promise = group.next().makePromise(of: ByteBuffer.self)
|
||||
let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.add(handler: ByteCountingHandler(numBytes: stringToWrite.utf8.count, promise: promise))
|
||||
channel.pipeline.addHandler(ByteCountingHandler(numBytes: stringToWrite.utf8.count, promise: promise))
|
||||
}
|
||||
.connect(to: serverChannel.localAddress!).wait())
|
||||
|
||||
@@ -554,7 +554,7 @@ class EchoServerClientTest : XCTestCase {
|
||||
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: EchoAndEchoAgainAfterSomeTimeServer(time: .seconds(1), secondWriteDoneHandler: {
|
||||
channel.pipeline.addHandler(EchoAndEchoAgainAfterSomeTimeServer(time: .seconds(1), secondWriteDoneHandler: {
|
||||
dpGroup.leave()
|
||||
}))
|
||||
}.bind(host: "127.0.0.1", port: 0).wait())
|
||||
@@ -566,7 +566,7 @@ class EchoServerClientTest : XCTestCase {
|
||||
let str = "hi there"
|
||||
let countingHandler = ByteCountingHandler(numBytes: str.utf8.count, promise: group.next().makePromise())
|
||||
let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group)
|
||||
.channelInitializer { $0.pipeline.add(handler: countingHandler) }
|
||||
.channelInitializer { $0.pipeline.addHandler(countingHandler) }
|
||||
.connect(to: serverChannel.localAddress!).wait())
|
||||
|
||||
var buffer = clientChannel.allocator.buffer(capacity: str.utf8.count)
|
||||
@@ -644,7 +644,7 @@ class EchoServerClientTest : XCTestCase {
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelOption(ChannelOptions.socket(SocketOptionLevel(IPPROTO_TCP), TCP_NODELAY), value: 1)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: WriteWhenActiveHandler(str, dpGroup))
|
||||
channel.pipeline.addHandler(WriteWhenActiveHandler(str, dpGroup))
|
||||
}.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
defer {
|
||||
@@ -656,8 +656,8 @@ class EchoServerClientTest : XCTestCase {
|
||||
//.channelOption(ChannelOptions.autoRead, value: false)
|
||||
.channelOption(ChannelOptions.recvAllocator, value: FixedSizeRecvByteBufferAllocator(capacity: 2))
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.add(handler: WriteHandler()).flatMap {
|
||||
channel.pipeline.add(handler: countingHandler)
|
||||
channel.pipeline.addHandler(WriteHandler()).flatMap {
|
||||
channel.pipeline.addHandler(countingHandler)
|
||||
}
|
||||
}.connect(to: serverChannel.localAddress!).wait())
|
||||
defer {
|
||||
@@ -708,7 +708,7 @@ class EchoServerClientTest : XCTestCase {
|
||||
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: ErrorHandler(promise))
|
||||
channel.pipeline.addHandler(ErrorHandler(promise))
|
||||
}.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
defer {
|
||||
@@ -789,7 +789,7 @@ class EchoServerClientTest : XCTestCase {
|
||||
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: countingHandler)
|
||||
channel.pipeline.addHandler(countingHandler)
|
||||
}
|
||||
.bind(host: "127.0.0.1", port: 0)
|
||||
.wait())
|
||||
|
||||
@@ -42,7 +42,7 @@ class EmbeddedChannelTest: XCTestCase {
|
||||
|
||||
func testWriteInboundByteBufferReThrow() throws {
|
||||
let channel = EmbeddedChannel()
|
||||
_ = try channel.pipeline.add(handler: ExceptionThrowingInboundHandler()).wait()
|
||||
_ = try channel.pipeline.addHandler(ExceptionThrowingInboundHandler()).wait()
|
||||
do {
|
||||
try channel.writeInbound("msg")
|
||||
XCTFail()
|
||||
@@ -54,7 +54,7 @@ class EmbeddedChannelTest: XCTestCase {
|
||||
|
||||
func testWriteOutboundByteBufferReThrow() throws {
|
||||
let channel = EmbeddedChannel()
|
||||
_ = try channel.pipeline.add(handler: ExceptionThrowingOutboundHandler()).wait()
|
||||
_ = try channel.pipeline.addHandler(ExceptionThrowingOutboundHandler()).wait()
|
||||
do {
|
||||
try channel.writeOutbound("msg")
|
||||
XCTFail()
|
||||
@@ -80,7 +80,7 @@ class EmbeddedChannelTest: XCTestCase {
|
||||
func testCloseOnInactiveIsOk() throws {
|
||||
let channel = EmbeddedChannel()
|
||||
let inactiveHandler = CloseInChannelInactiveHandler()
|
||||
_ = try channel.pipeline.add(handler: inactiveHandler).wait()
|
||||
_ = try channel.pipeline.addHandler(inactiveHandler).wait()
|
||||
XCTAssertFalse(try channel.finish())
|
||||
|
||||
// channelInactive should fire only once.
|
||||
|
||||
@@ -349,7 +349,7 @@ public class EventLoopTest : XCTestCase {
|
||||
let serverChannelUp = group.next().makePromise(of: Void.self)
|
||||
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: WedgeOpenHandler(channelActivePromise: serverChannelUp) { promise in
|
||||
channel.pipeline.addHandler(WedgeOpenHandler(channelActivePromise: serverChannelUp) { promise in
|
||||
promiseQueue.sync { promises.append(promise) }
|
||||
})
|
||||
}
|
||||
@@ -365,7 +365,7 @@ public class EventLoopTest : XCTestCase {
|
||||
}
|
||||
let channel = try SocketChannel(eventLoop: loop, protocolFamily: AF_INET)
|
||||
try channel.eventLoop.submit {
|
||||
channel.pipeline.add(handler: wedgeHandler).flatMap {
|
||||
channel.pipeline.addHandler(wedgeHandler).flatMap {
|
||||
channel.register()
|
||||
}.flatMap {
|
||||
// connecting here to stop epoll from throwing EPOLLHUP at us
|
||||
@@ -515,7 +515,7 @@ public class EventLoopTest : XCTestCase {
|
||||
.bind(host: "localhost", port: 0).wait())
|
||||
let channel = try assertNoThrowWithValue(SocketChannel(eventLoop: eventLoop as! SelectableEventLoop,
|
||||
protocolFamily: serverSocket.localAddress!.protocolFamily))
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: assertHandler).wait() as Void)
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(assertHandler).wait() as Void)
|
||||
XCTAssertNoThrow(try channel.eventLoop.submit {
|
||||
channel.register().flatMap {
|
||||
channel.connect(to: serverSocket.localAddress!)
|
||||
|
||||
@@ -35,7 +35,7 @@ class FileRegionTest : XCTestCase {
|
||||
|
||||
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelInitializer { $0.pipeline.add(handler: countingHandler) }
|
||||
.childChannelInitializer { $0.pipeline.addHandler(countingHandler) }
|
||||
.bind(host: "127.0.0.1", port: 0)
|
||||
.wait())
|
||||
|
||||
@@ -75,7 +75,7 @@ class FileRegionTest : XCTestCase {
|
||||
|
||||
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelInitializer { $0.pipeline.add(handler: countingHandler) }
|
||||
.childChannelInitializer { $0.pipeline.addHandler(countingHandler) }
|
||||
.bind(host: "127.0.0.1", port: 0)
|
||||
.wait())
|
||||
|
||||
@@ -126,7 +126,7 @@ class FileRegionTest : XCTestCase {
|
||||
|
||||
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelInitializer { $0.pipeline.add(handler: countingHandler) }
|
||||
.childChannelInitializer { $0.pipeline.addHandler(countingHandler) }
|
||||
.bind(host: "127.0.0.1", port: 0)
|
||||
.wait())
|
||||
|
||||
|
||||
@@ -214,7 +214,7 @@ extension DummyResolver.Event: Equatable {
|
||||
|
||||
private func defaultChannelBuilder(loop: EventLoop, family: Int32) -> EventLoopFuture<Channel> {
|
||||
let channel = EmbeddedChannel(loop: loop as! EmbeddedEventLoop)
|
||||
XCTAssertNoThrow(try channel.pipeline.add(name: CONNECT_RECORDER, handler: ConnectRecorder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(ConnectRecorder(), name: CONNECT_RECORDER).wait())
|
||||
return loop.makeSucceededFuture(channel)
|
||||
}
|
||||
|
||||
@@ -562,7 +562,7 @@ public class HappyEyeballsTest : XCTestCase {
|
||||
let (eyeballer, resolver, loop) = buildEyeballer(host: "example.com", port: 80, connectTimeout: .hours(1)) {
|
||||
let channelFuture = defaultChannelBuilder(loop: $0, family: $1)
|
||||
channelFuture.whenSuccess { channel in
|
||||
try! channel.pipeline.add(name: CONNECT_DELAYER, handler: ConnectionDelayer(), first: true).wait()
|
||||
try! channel.pipeline.addHandler(ConnectionDelayer(), name: CONNECT_DELAYER, position: .first).wait()
|
||||
channels.append(channel)
|
||||
}
|
||||
return channelFuture
|
||||
@@ -631,7 +631,7 @@ public class HappyEyeballsTest : XCTestCase {
|
||||
let (eyeballer, resolver, loop) = buildEyeballer(host: "example.com", port: 80, connectTimeout: .hours(1)) {
|
||||
let channelFuture = defaultChannelBuilder(loop: $0, family: $1)
|
||||
channelFuture.whenSuccess { channel in
|
||||
try! channel.pipeline.add(name: CONNECT_DELAYER, handler: ConnectionDelayer(), first: true).wait()
|
||||
try! channel.pipeline.addHandler(ConnectionDelayer(), name: CONNECT_DELAYER, position: .first).wait()
|
||||
channels.append(channel)
|
||||
}
|
||||
return channelFuture
|
||||
@@ -701,7 +701,7 @@ public class HappyEyeballsTest : XCTestCase {
|
||||
let (eyeballer, resolver, loop) = buildEyeballer(host: "example.com", port: 80, connectTimeout: .hours(1)) {
|
||||
let channelFuture = defaultChannelBuilder(loop: $0, family: $1)
|
||||
channelFuture.whenSuccess { channel in
|
||||
try! channel.pipeline.add(name: CONNECT_DELAYER, handler: ConnectionDelayer(), first: true).wait()
|
||||
try! channel.pipeline.addHandler(ConnectionDelayer(), name: CONNECT_DELAYER, position: .first).wait()
|
||||
channels.append(channel)
|
||||
}
|
||||
return channelFuture
|
||||
@@ -784,7 +784,7 @@ public class HappyEyeballsTest : XCTestCase {
|
||||
let (eyeballer, resolver, loop) = buildEyeballer(host: "example.com", port: 80, connectTimeout: .milliseconds(100)) {
|
||||
let channelFuture = defaultChannelBuilder(loop: $0, family: $1)
|
||||
channelFuture.whenSuccess { channel in
|
||||
try! channel.pipeline.add(name: CONNECT_DELAYER, handler: ConnectionDelayer(), first: true).wait()
|
||||
try! channel.pipeline.addHandler(ConnectionDelayer(), name: CONNECT_DELAYER, position: .first).wait()
|
||||
channels.append(channel)
|
||||
}
|
||||
return channelFuture
|
||||
@@ -829,7 +829,7 @@ public class HappyEyeballsTest : XCTestCase {
|
||||
let (eyeballer, resolver, loop) = buildEyeballer(host: "example.com", port: 80, connectTimeout: .milliseconds(100)) {
|
||||
let channelFuture = defaultChannelBuilder(loop: $0, family: $1)
|
||||
channelFuture.whenSuccess { channel in
|
||||
try! channel.pipeline.add(name: CONNECT_DELAYER, handler: ConnectionDelayer(), first: true).wait()
|
||||
try! channel.pipeline.addHandler(ConnectionDelayer(), name: CONNECT_DELAYER, position: .first).wait()
|
||||
channels.append(channel)
|
||||
}
|
||||
return channelFuture
|
||||
@@ -884,7 +884,7 @@ public class HappyEyeballsTest : XCTestCase {
|
||||
let (eyeballer, resolver, loop) = buildEyeballer(host: "example.com", port: 80, connectTimeout: .hours(1)) {
|
||||
let channelFuture = defaultChannelBuilder(loop: $0, family: $1)
|
||||
channelFuture.whenSuccess { channel in
|
||||
try! channel.pipeline.add(name: CONNECT_DELAYER, handler: ConnectionDelayer(), first: true).wait()
|
||||
try! channel.pipeline.addHandler(ConnectionDelayer(), name: CONNECT_DELAYER, position: .first).wait()
|
||||
channels.append(channel)
|
||||
}
|
||||
return channelFuture
|
||||
@@ -930,7 +930,7 @@ public class HappyEyeballsTest : XCTestCase {
|
||||
let (eyeballer, resolver, loop) = buildEyeballer(host: "example.com", port: 80, connectTimeout: .milliseconds(100)) {
|
||||
let channelFuture = defaultChannelBuilder(loop: $0, family: $1)
|
||||
channelFuture.whenSuccess { channel in
|
||||
try! channel.pipeline.add(name: CONNECT_DELAYER, handler: ConnectionDelayer(), first: true).wait()
|
||||
try! channel.pipeline.addHandler(ConnectionDelayer(), name: CONNECT_DELAYER, position: .first).wait()
|
||||
channels.append(channel)
|
||||
}
|
||||
return channelFuture
|
||||
@@ -975,7 +975,7 @@ public class HappyEyeballsTest : XCTestCase {
|
||||
let (eyeballer, resolver, loop) = buildEyeballer(host: "example.com", port: 80) {
|
||||
let channelFuture = defaultChannelBuilder(loop: $0, family: $1)
|
||||
channelFuture.whenSuccess { channel in
|
||||
try! channel.pipeline.add(name: CONNECT_DELAYER, handler: ConnectionDelayer(), first: true).wait()
|
||||
try! channel.pipeline.addHandler(ConnectionDelayer(), name: CONNECT_DELAYER, position: .first).wait()
|
||||
channels.append(channel)
|
||||
}
|
||||
return channelFuture
|
||||
@@ -1025,7 +1025,7 @@ public class HappyEyeballsTest : XCTestCase {
|
||||
let (eyeballer, resolver, loop) = buildEyeballer(host: "example.com", port: 80) {
|
||||
let channelFuture = defaultChannelBuilder(loop: $0, family: $1)
|
||||
channelFuture.whenSuccess { channel in
|
||||
try! channel.pipeline.add(name: CONNECT_DELAYER, handler: ConnectionDelayer(), first: true).wait()
|
||||
try! channel.pipeline.addHandler(ConnectionDelayer(), name: CONNECT_DELAYER, position: .first).wait()
|
||||
channels.append(channel)
|
||||
}
|
||||
return channelFuture
|
||||
@@ -1145,7 +1145,7 @@ public class HappyEyeballsTest : XCTestCase {
|
||||
let (eyeballer, resolver, loop) = buildEyeballer(host: "example.com", port: 80, connectTimeout: .milliseconds(250)) {
|
||||
let channelFuture = defaultChannelBuilder(loop: $0, family: $1)
|
||||
channelFuture.whenSuccess { channel in
|
||||
try! channel.pipeline.add(name: CONNECT_DELAYER, handler: ConnectionDelayer(), first: true).wait()
|
||||
try! channel.pipeline.addHandler(ConnectionDelayer(), name: CONNECT_DELAYER, position: .first).wait()
|
||||
channels.append(channel)
|
||||
}
|
||||
return channelFuture
|
||||
@@ -1194,7 +1194,7 @@ public class HappyEyeballsTest : XCTestCase {
|
||||
let (eyeballer, resolver, loop) = buildEyeballer(host: "example.com", port: 80, connectTimeout: .milliseconds(50)) {
|
||||
let channelFuture = defaultChannelBuilder(loop: $0, family: $1)
|
||||
channelFuture.whenSuccess { channel in
|
||||
try! channel.pipeline.add(name: CONNECT_DELAYER, handler: ConnectionDelayer(), first: true).wait()
|
||||
try! channel.pipeline.addHandler(ConnectionDelayer(), name: CONNECT_DELAYER, position: .first).wait()
|
||||
channels.append(channel)
|
||||
}
|
||||
return channelFuture
|
||||
|
||||
@@ -77,8 +77,8 @@ class IdleStateHandlerTest : XCTestCase {
|
||||
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: handler).flatMap { f in
|
||||
channel.pipeline.add(handler: TestWriteHandler(writeToChannel, assertEventFn))
|
||||
channel.pipeline.addHandler(handler).flatMap { f in
|
||||
channel.pipeline.addHandler(TestWriteHandler(writeToChannel, assertEventFn))
|
||||
}
|
||||
}.bind(host: "127.0.0.1", port: 0).wait())
|
||||
|
||||
@@ -161,8 +161,8 @@ class IdleStateHandlerTest : XCTestCase {
|
||||
}
|
||||
let eventHandler = EventHandler()
|
||||
let channel = EmbeddedChannel()
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: IdleStateHandler()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: eventHandler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(IdleStateHandler()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(eventHandler).wait())
|
||||
|
||||
channel.pipeline.fireChannelRegistered()
|
||||
channel.pipeline.fireChannelActive()
|
||||
|
||||
@@ -27,7 +27,7 @@ final class PromiseOnReadHandler: ChannelInboundHandler {
|
||||
|
||||
func channelRead(ctx: ChannelHandlerContext, data: NIOAny) {
|
||||
self.promise.succeed(self.unwrapInboundIn(data))
|
||||
_ = ctx.pipeline.remove(ctx: ctx)
|
||||
_ = ctx.pipeline.removeHandler(ctx: ctx)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ final class MulticastTest: XCTestCase {
|
||||
|
||||
private func assertDatagramReaches(multicastChannel: Channel, sender: Channel, multicastAddress: SocketAddress, file: StaticString = #file, line: UInt = #line) throws {
|
||||
let receivedMulticastDatagram = multicastChannel.eventLoop.makePromise(of: AddressedEnvelope<ByteBuffer>.self)
|
||||
XCTAssertNoThrow(try multicastChannel.pipeline.add(handler: PromiseOnReadHandler(promise: receivedMulticastDatagram)).wait())
|
||||
XCTAssertNoThrow(try multicastChannel.pipeline.addHandler(PromiseOnReadHandler(promise: receivedMulticastDatagram)).wait())
|
||||
|
||||
var messageBuffer = sender.allocator.buffer(capacity: 24)
|
||||
messageBuffer.writeStaticString("hello, world!")
|
||||
@@ -143,7 +143,7 @@ final class MulticastTest: XCTestCase {
|
||||
file: StaticString = #file, line: UInt = #line) throws {
|
||||
let timeoutPromise = multicastChannel.eventLoop.makePromise(of: Void.self)
|
||||
let receivedMulticastDatagram = multicastChannel.eventLoop.makePromise(of: AddressedEnvelope<ByteBuffer>.self)
|
||||
XCTAssertNoThrow(try multicastChannel.pipeline.add(handler: PromiseOnReadHandler(promise: receivedMulticastDatagram)).wait())
|
||||
XCTAssertNoThrow(try multicastChannel.pipeline.addHandler(PromiseOnReadHandler(promise: receivedMulticastDatagram)).wait())
|
||||
|
||||
// If we receive a datagram, or the reader promise fails, we must fail the timeoutPromise.
|
||||
receivedMulticastDatagram.futureResult.map { (_: AddressedEnvelope<ByteBuffer>) in
|
||||
|
||||
@@ -255,7 +255,7 @@ class SelectorTest: XCTestCase {
|
||||
reconnectedChannelsHaveRead.append(p.futureResult)
|
||||
let newChannel = ClientBootstrap(group: ctx.eventLoop)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.add(handler: HappyWhenReadHandler(hasReConnectEventLoopTickFinished: self.hasReConnectEventLoopTickFinished,
|
||||
channel.pipeline.addHandler(HappyWhenReadHandler(hasReConnectEventLoopTickFinished: self.hasReConnectEventLoopTickFinished,
|
||||
didReadPromise: p)).map {
|
||||
hasBeenAdded = true
|
||||
}
|
||||
@@ -337,7 +337,7 @@ class SelectorTest: XCTestCase {
|
||||
let tempDir = createTemporaryDirectory()
|
||||
let secondServerChannel = try! ServerBootstrap(group: el)
|
||||
.childChannelInitializer { channel in
|
||||
channel.pipeline.add(handler: ServerHandler(allServerChannels: allServerChannels,
|
||||
channel.pipeline.addHandler(ServerHandler(allServerChannels: allServerChannels,
|
||||
numberOfConnectedChannels: numberOfConnectedChannels))
|
||||
}
|
||||
.bind(to: SocketAddress(unixDomainSocketPath: "\(tempDir)/server-sock.uds"))
|
||||
@@ -349,7 +349,7 @@ class SelectorTest: XCTestCase {
|
||||
ClientBootstrap(group: el)
|
||||
.channelOption(ChannelOptions.allowRemoteHalfClosure, value: true)
|
||||
.channelInitializer { channel in
|
||||
channel.pipeline.add(handler: CloseEveryOtherAndOpenNewOnesHandler(allChannels: allChannels,
|
||||
channel.pipeline.addHandler(CloseEveryOtherAndOpenNewOnesHandler(allChannels: allChannels,
|
||||
hasReConnectEventLoopTickFinished: hasReConnectEventLoopTickFinished,
|
||||
serverAddress: secondServerChannel.localAddress!,
|
||||
everythingWasReadPromise: everythingWasReadPromise))
|
||||
|
||||
@@ -154,7 +154,7 @@ public class SocketChannelTest : XCTestCase {
|
||||
let promise = serverChannel.eventLoop.makePromise(of: IOError.self)
|
||||
|
||||
XCTAssertNoThrow(try serverChannel.eventLoop.submit {
|
||||
serverChannel.pipeline.add(handler: AcceptHandler(promise)).flatMap {
|
||||
serverChannel.pipeline.addHandler(AcceptHandler(promise)).flatMap {
|
||||
serverChannel.register()
|
||||
}.flatMap {
|
||||
serverChannel.bind(to: try! SocketAddress(ipAddress: "127.0.0.1", port: 0))
|
||||
@@ -236,7 +236,7 @@ public class SocketChannelTest : XCTestCase {
|
||||
eventLoop: eventLoop as! SelectableEventLoop))
|
||||
let promise = channel.eventLoop.makePromise(of: Void.self)
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: ActiveVerificationHandler(promise)).flatMap {
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(ActiveVerificationHandler(promise)).flatMap {
|
||||
channel.register()
|
||||
}.flatMap {
|
||||
channel.connect(to: try! SocketAddress(ipAddress: "127.0.0.1", port: 9999))
|
||||
@@ -451,7 +451,7 @@ public class SocketChannelTest : XCTestCase {
|
||||
XCTAssertFalse(closePromise.futureResult.isFulfilled)
|
||||
}
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: NotificationOrderHandler()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(NotificationOrderHandler()).wait())
|
||||
|
||||
// We need to call submit {...} here to ensure then {...} is called while on the EventLoop already to not have
|
||||
// a ECONNRESET sneak in.
|
||||
@@ -523,7 +523,7 @@ public class SocketChannelTest : XCTestCase {
|
||||
|
||||
let handler = AddressVerificationHandler(promise: group.next().makePromise())
|
||||
let serverChannel = try assertNoThrowWithValue(ServerBootstrap(group: group)
|
||||
.childChannelInitializer { $0.pipeline.add(handler: handler) }
|
||||
.childChannelInitializer { $0.pipeline.addHandler(handler) }
|
||||
.bind(host: "127.0.0.1", port: 0)
|
||||
.wait())
|
||||
defer { XCTAssertNoThrow(try serverChannel.close().wait()) }
|
||||
@@ -595,7 +595,7 @@ public class SocketChannelTest : XCTestCase {
|
||||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.serverChannelOption(ChannelOptions.backlog, value: 256)
|
||||
.serverChannelOption(ChannelOptions.autoRead, value: false)
|
||||
.serverChannelInitializer { channel in channel.pipeline.add(handler: ErrorHandler(serverPromise)) }
|
||||
.serverChannelInitializer { channel in channel.pipeline.addHandler(ErrorHandler(serverPromise)) }
|
||||
.bind(host: "127.0.0.1", port: 0)
|
||||
.wait())
|
||||
|
||||
|
||||
@@ -340,7 +340,7 @@ class EndToEndTests: XCTestCase {
|
||||
let recorder = WebSocketRecorderHandler()
|
||||
let basicUpgrader = WebSocketUpgrader(shouldUpgrade: { head in HTTPHeaders() },
|
||||
upgradePipelineHandler: { (channel, req) in
|
||||
channel.pipeline.add(handler: recorder)
|
||||
channel.pipeline.addHandler(recorder)
|
||||
|
||||
})
|
||||
let (loop, server, client) = createTestFixtures(upgraders: [basicUpgrader])
|
||||
@@ -360,7 +360,7 @@ class EndToEndTests: XCTestCase {
|
||||
expectedResponseHeaders: ["Upgrade: websocket", "Sec-WebSocket-Accept: OfS0wDaT5NoxF2gqm7Zj2YtetzM=", "Connection: upgrade"])
|
||||
|
||||
// Put a frame encoder in the client pipeline.
|
||||
XCTAssertNoThrow(try client.pipeline.add(handler: WebSocketFrameEncoder()).wait())
|
||||
XCTAssertNoThrow(try client.pipeline.addHandler(WebSocketFrameEncoder()).wait())
|
||||
|
||||
var data = client.allocator.buffer(capacity: 12)
|
||||
data.writeString("hello, world")
|
||||
@@ -405,7 +405,7 @@ class EndToEndTests: XCTestCase {
|
||||
let recorder = WebSocketRecorderHandler()
|
||||
let basicUpgrader = WebSocketUpgrader(shouldUpgrade: { head in HTTPHeaders() },
|
||||
upgradePipelineHandler: { (channel, req) in
|
||||
channel.pipeline.add(handler: recorder)
|
||||
channel.pipeline.addHandler(recorder)
|
||||
|
||||
})
|
||||
let (loop, server, client) = createTestFixtures(upgraders: [basicUpgrader])
|
||||
@@ -451,7 +451,7 @@ class EndToEndTests: XCTestCase {
|
||||
let basicUpgrader = WebSocketUpgrader(automaticErrorHandling: false,
|
||||
shouldUpgrade: { head in HTTPHeaders() },
|
||||
upgradePipelineHandler: { (channel, req) in
|
||||
channel.pipeline.add(handler: recorder)
|
||||
channel.pipeline.addHandler(recorder)
|
||||
|
||||
})
|
||||
let (loop, server, client) = createTestFixtures(upgraders: [basicUpgrader])
|
||||
|
||||
@@ -65,8 +65,8 @@ public class WebSocketFrameDecoderTest: XCTestCase {
|
||||
self.decoderChannel = EmbeddedChannel()
|
||||
self.encoderChannel = EmbeddedChannel()
|
||||
self.buffer = decoderChannel.allocator.buffer(capacity: 128)
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: ByteToMessageHandler(WebSocketFrameDecoder())).wait())
|
||||
XCTAssertNoThrow(try self.encoderChannel.pipeline.add(handler: WebSocketFrameEncoder()).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(ByteToMessageHandler(WebSocketFrameDecoder())).wait())
|
||||
XCTAssertNoThrow(try self.encoderChannel.pipeline.addHandler(WebSocketFrameEncoder()).wait())
|
||||
}
|
||||
|
||||
public override func tearDown() {
|
||||
@@ -110,14 +110,14 @@ public class WebSocketFrameDecoderTest: XCTestCase {
|
||||
throw ChannelError.unremovableHandler
|
||||
}
|
||||
}.flatMap {
|
||||
self.decoderChannel.pipeline.remove(handler: $0)
|
||||
self.decoderChannel.pipeline.removeHandler($0)
|
||||
}
|
||||
|
||||
// we need to run the event loop here because removal is not synchronous
|
||||
(self.decoderChannel.eventLoop as! EmbeddedEventLoop).run()
|
||||
|
||||
XCTAssertNoThrow(try f.flatMap {
|
||||
self.decoderChannel.pipeline.add(handler: handler)
|
||||
self.decoderChannel.pipeline.addHandler(handler)
|
||||
}.wait())
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ public class WebSocketFrameDecoderTest: XCTestCase {
|
||||
// We need a new decoder channel here, because the max length would otherwise trigger an error.
|
||||
_ = try! self.decoderChannel.finish()
|
||||
self.decoderChannel = EmbeddedChannel()
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: ByteToMessageHandler(WebSocketFrameDecoder(maxFrameSize: 80000))).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(ByteToMessageHandler(WebSocketFrameDecoder(maxFrameSize: 80000))).wait())
|
||||
|
||||
self.buffer.writeBytes(Array(repeating: UInt8(4), count: 66000))
|
||||
let frame = WebSocketFrame(fin: true,
|
||||
@@ -233,7 +233,7 @@ public class WebSocketFrameDecoderTest: XCTestCase {
|
||||
}
|
||||
|
||||
public func testDecoderRejectsOverlongFrames() throws {
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: WebSocketFrameEncoder(), first: true).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(WebSocketFrameEncoder(), position: .first).wait())
|
||||
|
||||
// A fake frame header that claims that the length of the frame is 16385 bytes,
|
||||
// larger than the frame max.
|
||||
@@ -254,7 +254,7 @@ public class WebSocketFrameDecoderTest: XCTestCase {
|
||||
}
|
||||
|
||||
public func testDecoderRejectsFragmentedControlFrames() throws {
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: WebSocketFrameEncoder(), first: true).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(WebSocketFrameEncoder(), position: .first).wait())
|
||||
|
||||
// A fake frame header that claims this is a fragmented ping frame.
|
||||
self.buffer.writeBytes([0x09, 0x00])
|
||||
@@ -274,7 +274,7 @@ public class WebSocketFrameDecoderTest: XCTestCase {
|
||||
}
|
||||
|
||||
public func testDecoderRejectsMultibyteControlFrameLengths() throws {
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: WebSocketFrameEncoder(), first: true).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(WebSocketFrameEncoder(), position: .first).wait())
|
||||
|
||||
// A fake frame header that claims this is a ping frame with 126 bytes of data.
|
||||
self.buffer.writeBytes([0x89, 0x7E, 0x00, 0x7E])
|
||||
@@ -295,8 +295,8 @@ public class WebSocketFrameDecoderTest: XCTestCase {
|
||||
|
||||
func testIgnoresFurtherDataAfterRejectedFrame() throws {
|
||||
let swallower = CloseSwallower()
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: WebSocketFrameEncoder(), first: true).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: swallower, first: true).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(WebSocketFrameEncoder(), position: .first).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(swallower, position: .first).wait())
|
||||
|
||||
// A fake frame header that claims this is a fragmented ping frame.
|
||||
self.buffer.writeBytes([0x09, 0x00])
|
||||
@@ -327,12 +327,12 @@ public class WebSocketFrameDecoderTest: XCTestCase {
|
||||
swallower.allowClose()
|
||||
|
||||
// Take the handler out for cleanliness.
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.remove(handler: swallower).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.removeHandler(swallower).wait())
|
||||
}
|
||||
|
||||
public func testClosingSynchronouslyOnChannelRead() throws {
|
||||
// We're going to send a connectionClose frame and confirm we only see it once.
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: SynchronousCloser()).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(SynchronousCloser()).wait())
|
||||
|
||||
var errorCodeBuffer = self.encoderChannel.allocator.buffer(capacity: 4)
|
||||
errorCodeBuffer.write(webSocketErrorCode: .normalClosure)
|
||||
@@ -356,7 +356,7 @@ public class WebSocketFrameDecoderTest: XCTestCase {
|
||||
// We need to insert a decoder that doesn't do error handling. We still insert
|
||||
// an encoder because we want to fail gracefully if a frame is written.
|
||||
self.swapDecoder(for: ByteToMessageHandler(WebSocketFrameDecoder(automaticErrorHandling: false)))
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: WebSocketFrameEncoder(), first: true).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(WebSocketFrameEncoder(), position: .first).wait())
|
||||
|
||||
// A fake frame header that claims that the length of the frame is 16385 bytes,
|
||||
// larger than the frame max.
|
||||
@@ -380,7 +380,7 @@ public class WebSocketFrameDecoderTest: XCTestCase {
|
||||
// We need to insert a decoder that doesn't do error handling. We still insert
|
||||
// an encoder because we want to fail gracefully if a frame is written.
|
||||
self.swapDecoder(for: ByteToMessageHandler(WebSocketFrameDecoder(automaticErrorHandling: false)))
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: WebSocketFrameEncoder(), first: true).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(WebSocketFrameEncoder(), position: .first).wait())
|
||||
|
||||
// A fake frame header that claims this is a fragmented ping frame.
|
||||
self.buffer.writeBytes([0x09, 0x00])
|
||||
@@ -403,7 +403,7 @@ public class WebSocketFrameDecoderTest: XCTestCase {
|
||||
// We need to insert a decoder that doesn't do error handling. We still insert
|
||||
// an encoder because we want to fail gracefully if a frame is written.
|
||||
self.swapDecoder(for: ByteToMessageHandler(WebSocketFrameDecoder(automaticErrorHandling: false)))
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: WebSocketFrameEncoder(), first: true).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(WebSocketFrameEncoder(), position: .first).wait())
|
||||
|
||||
// A fake frame header that claims this is a ping frame with 126 bytes of data.
|
||||
self.buffer.writeBytes([0x89, 0x7E, 0x00, 0x7E])
|
||||
@@ -426,7 +426,7 @@ public class WebSocketFrameDecoderTest: XCTestCase {
|
||||
// We need to insert a decoder that doesn't do error handling. We still insert
|
||||
// an encoder because we want to fail gracefully if a frame is written.
|
||||
self.swapDecoder(for: ByteToMessageHandler(WebSocketFrameDecoder(automaticErrorHandling: false)))
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: WebSocketFrameEncoder(), first: true).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(WebSocketFrameEncoder(), position: .first).wait())
|
||||
|
||||
// A fake frame header that claims this is a fragmented ping frame.
|
||||
self.buffer.writeBytes([0x09, 0x00])
|
||||
@@ -458,8 +458,8 @@ public class WebSocketFrameDecoderTest: XCTestCase {
|
||||
// We need to insert a decoder that doesn't do error handling, and then a separate error
|
||||
// handler.
|
||||
self.swapDecoder(for: ByteToMessageHandler(WebSocketFrameDecoder(automaticErrorHandling: false)))
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: WebSocketFrameEncoder(), first: true).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: WebSocketProtocolErrorHandler()).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(WebSocketFrameEncoder(), position: .first).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(WebSocketProtocolErrorHandler()).wait())
|
||||
|
||||
// A fake frame header that claims that the length of the frame is 16385 bytes,
|
||||
// larger than the frame max.
|
||||
@@ -483,8 +483,8 @@ public class WebSocketFrameDecoderTest: XCTestCase {
|
||||
// We need to insert a decoder that doesn't do error handling, and then a separate error
|
||||
// handler.
|
||||
self.swapDecoder(for: ByteToMessageHandler(WebSocketFrameDecoder(automaticErrorHandling: false)))
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: WebSocketFrameEncoder(), first: true).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: WebSocketProtocolErrorHandler()).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(WebSocketFrameEncoder(), position: .first).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(WebSocketProtocolErrorHandler()).wait())
|
||||
|
||||
// A fake frame header that claims this is a fragmented ping frame.
|
||||
self.buffer.writeBytes([0x09, 0x00])
|
||||
@@ -507,8 +507,8 @@ public class WebSocketFrameDecoderTest: XCTestCase {
|
||||
// We need to insert a decoder that doesn't do error handling, and then a separate error
|
||||
// handler.
|
||||
self.swapDecoder(for: ByteToMessageHandler(WebSocketFrameDecoder(automaticErrorHandling: false)))
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: WebSocketFrameEncoder(), first: true).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: WebSocketProtocolErrorHandler()).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(WebSocketFrameEncoder(), position: .first).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(WebSocketProtocolErrorHandler()).wait())
|
||||
|
||||
// A fake frame header that claims this is a ping frame with 126 bytes of data.
|
||||
self.buffer.writeBytes([0x89, 0x7E, 0x00, 0x7E])
|
||||
@@ -532,9 +532,9 @@ public class WebSocketFrameDecoderTest: XCTestCase {
|
||||
// We need to insert a decoder that doesn't do error handling, and then a separate error
|
||||
// handler.
|
||||
self.swapDecoder(for: ByteToMessageHandler(WebSocketFrameDecoder(automaticErrorHandling: false)))
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: WebSocketFrameEncoder(), first: true).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: WebSocketProtocolErrorHandler()).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.add(handler: swallower, first: true).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(WebSocketFrameEncoder(), position: .first).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(WebSocketProtocolErrorHandler()).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.addHandler(swallower, position: .first).wait())
|
||||
|
||||
// A fake frame header that claims this is a fragmented ping frame.
|
||||
self.buffer.writeBytes([0x09, 0x00])
|
||||
@@ -565,6 +565,6 @@ public class WebSocketFrameDecoderTest: XCTestCase {
|
||||
swallower.allowClose()
|
||||
|
||||
// Take the handler out for cleanliness.
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.remove(handler: swallower).wait())
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.removeHandler(swallower).wait())
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class WebSocketFrameEncoderTest: XCTestCase {
|
||||
public override func setUp() {
|
||||
self.channel = EmbeddedChannel()
|
||||
self.buffer = channel.allocator.buffer(capacity: 128)
|
||||
XCTAssertNoThrow(try self.channel.pipeline.add(handler: WebSocketFrameEncoder()).wait())
|
||||
XCTAssertNoThrow(try self.channel.pipeline.addHandler(WebSocketFrameEncoder()).wait())
|
||||
}
|
||||
|
||||
public override func tearDown() {
|
||||
|
||||
@@ -58,3 +58,8 @@
|
||||
- `CircularBuffer` and `MarkedCircularBuffer`'s indices are now opaque
|
||||
- all `ChannelOption`s are now required to be `Equatable`
|
||||
- rename `FileHandle` to `NIOFileHandle`
|
||||
- rename all `ChannelPipeline.add(name:handler:...)`s to `ChannelPipeline.addHandler(_:name:...)`
|
||||
- rename all `ChannelPipeline.remove(...)`s to `ChannelPipeline.removeHandler(...)`
|
||||
- change `ChannelPipeline.addHandler[s](_:first:)` to `ChannelPipeline.addHandler(_:postion:)` where `position` can be `.first`, `.last`, `.before(ChannelHandler)`, and `.after(ChannelHandler)`
|
||||
- change `ChannelPipeline.addHandler(_:before:)` to `ChannelPipeline.addHandler(_:postion:)` where `position` can be `.first`, `.last`, `.before(ChannelHandler)`, and `.after(ChannelHandler)`
|
||||
- change `ChannelPipeline.addHandler(_:after:)` to `ChannelPipeline.addHandler(_:postion:)` where `position` can be `.first`, `.last`, `.before(ChannelHandler)`, and `.after(ChannelHandler)`
|
||||
Reference in new issue
Block a user