fixed uncached 404

This commit is contained in:
Ben Zörb 2015-02-04 09:22:47 +01:00
parent d6c6de0f83
commit 909d1a3773
1 changed files with 26 additions and 3 deletions

View File

@ -2,8 +2,8 @@
namespace Gregwar\CaptchaBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
@ -36,8 +36,9 @@ class CaptchaController extends Controller
}
}
if (!$isOk) {
throw $this->createNotFoundException('Unable to generate a captcha via an URL with this session key.');
return $this->error($options);
}
/* @var \Gregwar\CaptchaBundle\Generator\CaptchaGenerator $generator */
@ -58,4 +59,26 @@ class CaptchaController extends Controller
return $response;
}
/**
* Returns an empty image with status code 428 Precondition Required
*
* @param array $options
*
* @return Response
*/
protected function error($options)
{
/* @var \Gregwar\CaptchaBundle\Generator\CaptchaGenerator $generator */
$generator = $this->container->get('gregwar_captcha.generator');
$generator->setPhrase('');
$response = new Response($generator->generate($options));
$response->setStatusCode(428);
$response->headers->set('Content-type', 'image/jpeg');
$response->headers->set('Pragma', 'no-cache');
$response->headers->set('Cache-Control', 'no-cache');
return $response;
}
}