public function open()
 {
     $this->opening = true;
     $file = $this->filesystem->file($this->getRandomFilename());
     return $file->exists()->then(function () {
         return $this->open();
     }, function () use($file) {
         return $file->create()->open('cw')->then(function ($stream) {
             $this->open = true;
             $this->opening = false;
             $this->stream = $stream;
         });
     });
 }
 public function __invoke(Request $request, Response $response)
 {
     if ($request->getPath() == self::SSE_PATH) {
         $this->handleSse($request, $response);
         return;
     }
     if ($request->getPath() == self::LOOKED_PATH) {
         $this->handleLookup($response, $request->getQuery()['host']);
         return;
     }
     $this->files->then(function (\SplObjectStorage $files) use($request, $response) {
         foreach ($files as $file) {
             if ($file->getPath() == WEBROOT . $request->getPath()) {
                 $this->handleFile($file, $response);
                 return;
             }
         }
         $this->handleFile($this->filesystem->file(WEBROOT . DIRECTORY_SEPARATOR . '404.txt'), $response);
         return;
     });
 }