summaryrefslogtreecommitdiff
path: root/src/Http/Response.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Http/Response.php')
-rw-r--r--src/Http/Response.php23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Http/Response.php b/src/Http/Response.php
index 58cd7662..1a7c8209 100644
--- a/src/Http/Response.php
+++ b/src/Http/Response.php
@@ -121,4 +121,27 @@ class Response extends SymfonyResponse implements ResponseInterface
return $new;
}
+
+ /**
+ * Return an redirect instance
+ *
+ * This method retains the immutability of the message and returns
+ * an instance with the updated status and headers
+ *
+ * @param string $path
+ * @param int $status
+ * @param array $headers
+ * @return Response
+ */
+ public function redirectTo($path, $status = 302, $headers = [])
+ {
+ $response = $this->withStatus($status);
+ $response = $response->withHeader('location', $path);
+
+ foreach ($headers as $name => $value) {
+ $response = $response->withAddedHeader($name, $value);
+ }
+
+ return $response;
+ }
}