|
@@ -535,6 +535,26 @@ class Response
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Modifies the response so that it conforms to the rules defined for a redirect status code.
|
|
|
+ *
|
|
|
+ * @see http://tools.ietf.org/html/rfc2616#section-10.3.5
|
|
|
+ */
|
|
|
+ public function setRedirect($url, $status = 302)
|
|
|
+ {
|
|
|
+ if (empty($url)) {
|
|
|
+ throw new \InvalidArgumentException('Cannot redirect to an empty URL.');
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->setStatusCode($status);
|
|
|
+ if (!$this->isRedirect()) {
|
|
|
+ throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $status));
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->headers->set('Location', $url);
|
|
|
+ $this->setContent(sprintf('<html><head><meta http-equiv="refresh" content="1;url=%s"/></head></html>', htmlspecialchars($url, ENT_QUOTES)));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Returns true if the response includes a Vary header.
|
|
|
*
|