protected function handleStatusCodeException(StatusCode\StatusCodeException $e, ResponseInterface $response) { $response->setStatus($e->getStatusCode()); if ($e instanceof StatusCode\MethodNotAllowedException) { $allowedMethods = $e->getAllowedMethods(); if (!empty($allowedMethods)) { $response->setHeader('Allow', implode(', ', $allowedMethods)); } } elseif ($e instanceof StatusCode\UnauthorizedException) { $type = $e->getType(); $parameters = $e->getParameters(); if (!empty($type)) { if (!empty($parameters)) { $response->setHeader('WWW-Authenticate', $type . ' ' . Authentication::encodeParameters($parameters)); } else { $response->setHeader('WWW-Authenticate', $type); } } } }