         logger.error("Did not publish Bonjour service: \(errorDict)")
     }
 }
+
+extension ChannelPipeline {
+    func addHapClientHandlers(application: ChannelHandler, controller: ChannelHandler) -> EventLoopFuture<Void> {
+        addHandler(CryptographerHandler()).flatMap {
+            self.addHandler(EventHandler()).flatMap {
+                self.configureHTTPServerPipeline(withErrorHandling: true).flatMap {
+                    self.addHandler(controller).flatMap {
+                        self.addHandler(RequestHandler()).flatMap {
+                            self.addHandler(UpgradeEventHandler()).flatMap {
+                                self.addHandler(application)
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+}


            // Set the handlers that are applied to the accepted child `Channel`s.
            .childChannelInitializer { channel in
                channel.pipeline.addHandler(CryptographerHandler()).flatMap {
                    channel.pipeline.addHandler(EventHandler()).flatMap {
                        channel.pipeline.configureHTTPServerPipeline(withErrorHandling: true).flatMap {
                            // It's important we use the same handler for all accepted channels.
                            // The ControllerHandler is thread-safe!
                            channel.pipeline.addHandler(device.controllerHandler!).flatMap {
                                channel.pipeline.addHandler(RequestHandler()).flatMap {
                                    channel.pipeline.addHandler(UpgradeEventHandler()).flatMap {
                                        channel.pipeline.addHandler(applicationHandler)
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Enable TCP_NODELAY and SO_REUSEADDR for the accepted Channels

        device.controllerHandler = ControllerHandler()
        device.controllerHandler!.removeSubscriptions = device.removeSubscriberForAllCharacteristics

        let application = ApplicationHandler(responder: root(device: device))

        self.ownGroup = worker == nil
        self.group = worker ?? MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
