[HttpFoundation] Add headers arg to RedirectResponse

This commit is contained in:
Jordi Boggiano 2012-03-15 16:27:52 +01:00
parent 873da434cd
commit 1c86ad78ee

View File

@ -25,14 +25,15 @@ class RedirectResponse extends Response
/** /**
* Creates a redirect response so that it conforms to the rules defined for a redirect status code. * Creates a redirect response so that it conforms to the rules defined for a redirect status code.
* *
* @param string $url The URL to redirect to * @param string $url The URL to redirect to
* @param integer $status The status code (302 by default) * @param integer $status The status code (302 by default)
* @param array $headers The headers (Location is added with the given url)
* *
* @see http://tools.ietf.org/html/rfc2616#section-10.3 * @see http://tools.ietf.org/html/rfc2616#section-10.3
* *
* @api * @api
*/ */
public function __construct($url, $status = 302) public function __construct($url, $status = 302, $headers = array())
{ {
if (empty($url)) { if (empty($url)) {
throw new \InvalidArgumentException('Cannot redirect to an empty URL.'); throw new \InvalidArgumentException('Cannot redirect to an empty URL.');
@ -54,7 +55,7 @@ class RedirectResponse extends Response
</body> </body>
</html>', htmlspecialchars($url, ENT_QUOTES, 'UTF-8')), </html>', htmlspecialchars($url, ENT_QUOTES, 'UTF-8')),
$status, $status,
array('Location' => $url) array_merge(array('Location' => $url), $headers)
); );
if (!$this->isRedirect()) { if (!$this->isRedirect()) {