Last active
August 29, 2015 14:27
-
-
Save shengjie/fc8a6fa1e65536ba7a3e to your computer and use it in GitHub Desktop.
A simple solution for captureable redirect response. browser can handle this response easily
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\HttpFoundation\Response; | |
class MetaRedirectResponse extends Response | |
{ | |
/** | |
* Constructor. | |
* | |
* @param mixed $content The response content, see setContent() | |
* @param int $status The response status code | |
* @param array $headers An array of response headers | |
* | |
* @throws \InvalidArgumentException When the HTTP status code is not valid | |
* | |
* @api | |
*/ | |
public function __construct($url, $headers = array()) | |
{ | |
parent::__construct(sprintf( | |
'<html><head><meta charset="UTF-8" /><meta http-equiv="refresh" content="0;url=%1$s" /><title>Redirecting to %1$s</title></head><body>Redirecting to <a href="%1$s">%1$s</a>.<script type="text/javascript">location.href="%1$s";</script></body></html>', $url) | |
, 200, | |
$headers | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using following code to capture meta redirect response.