@@ -17,6 +17,8 @@ Some standard use cases, however, make this un-wieldy:
1717- Returning a response containing JSON; in this case, you likely want to provide the data to
1818 seriazlize to JSON, not a stream containing serialized JSON.
1919- Returning a response with no content; in this case, you don't want to bother with the body at all.
20+ - Returning a redirect response; in this case, you likely just want to specify the target for the
21+ ` Location ` header, and optionally the status code.
2022
2123Starting with version 1.1, Diactoros offers several custom response types and factories for
2224simplifying these common tasks.
@@ -95,6 +97,34 @@ $response = new EmptyResponse(201, [
9597$response = ( new EmptyResponse(201) )->withHeader('Location', $url);
9698```
9799
100+ ## Redirects
101+
102+ ` Zend\Diactoros\Response\RedirectResponse ` is a ` Zend\Diactoros\Response ` extension for producing
103+ redirect responses. The only required argument is a URI, which may be provided as either a string or
104+ ` Psr\Http\Message\UriInterface ` instance. By default, the status 302 is used, and no other headers
105+ are produced; you may alter these via the additional optional arguments:
106+
107+ ``` php
108+ class RedirectResponse extends Response
109+ {
110+ public function __construct($uri, $status = 302, array $headers = []);
111+ }
112+ ```
113+
114+ Typical usage is:
115+
116+ ``` php
117+ // 302 redirect:
118+ $response = new RedirectResponse('/user/login');
119+
120+ // 301 redirect:
121+ $response = new RedirectResponse('/user/login', 301);
122+
123+ // using a URI instance (e.g., by altering the request URI instance)
124+ $uri = $request->getUri();
125+ $response = new RedirectResponse($uri->withPath('/login'));
126+ ```
127+
98128## Creating custom responses
99129
100130PHP allows constructor overloading. What this means is that constructors of extending classes can
0 commit comments