/**
  * Recurse through the Routes until a match is found.
  *
  * When called multiple times (in a loop for instance)
  * this method will return a new matching route until
  * all routes have been processed.
  *
  * Once exhausted this function returns false and the
  * internal pointer is reset so the Router can be used
  * again.
  *
  * @return bool|Proem\Api\Routing\Route\Payload
  */
 public function route()
 {
     if ($route = $this->routes->current()) {
         $this->routes->next();
         $route->process($this->request);
         if ($route->isMatch() && $route->getPayload()->isPopulated()) {
             if ($route->hasCallback()) {
                 return $route->call($this->request);
             }
             return $route->getPayload();
         } else {
             return $this->route();
         }
     }
     $this->routes->rewind();
     return false;
 }
 /**
  * Send the HTTP headers to the client.
  */
 public function sendHeaders()
 {
     if (headers_sent()) {
         return;
     }
     if (in_array($this->httpStatus, [204, 304])) {
         $this->headers->remove('Content-Type');
     }
     header(sprintf('HTTP/%s %s %s', $this->httpVersion, $this->getHttpStatus(), $this->getHttpStatus(true)));
     foreach ($this->headers->all() as $index => $value) {
         header(sprintf('%s: %s', $index, $value));
     }
     header('Connection: close');
     flush();
 }