                 LogError("\(errorDescription)")
             }
         })
+    }
+    
+    private func startHTTPServer() -> Bool {
+        if _httpServer.safeToStart {
+            return _httpServer.startWithPort(_httpServerPort, bonjourName: nil)
+        }
+        
+        return false
+    }
+    
+    private func stopHTTPServer() -> Bool {
+        if _httpServer.safeToStop {
+            _httpServer.stop()
+            return true
+        }
+        
+        return false
     }
 }
 

    private func startStopHTTPServerIfNeeded(subscriptions: [String: Subscription]) {
        let httpServer = self._httpServer
        if subscriptions.count == 0 && httpServer.running {
            httpServer.stop()
        }
        else if subscriptions.count > 0 && !httpServer.running {
            var error: NSError?
            if !httpServer.startWithPort(_httpServerPort, bonjourName: nil) {
                let toAppend = error != nil && error?.localizedDescriptionOrNil != nil ? ": \(error!.localizedDescription)" : ""
                LogError("Error starting HTTP server" + toAppend)
            }
        }
    }

        return dataTask
    }
}

extension GCDWebServer {
    var safeToStart: Bool {
        // prevents a crash where although the http server reports running is false, attempting to start while GCDWebServer->_source4 is not null causes abort() to be called which kills the app. GCDWebServer.serverURL == nil is equivalent to GCDWebServer->_source4 == NULL.
        return !running && serverURL == nil
    }
    
    var safeToStop: Bool {
        // prevents a crash where http server must actually be running to stop it or abort() is called which kills the app.
        return running
    }
}
