add status code to System::externalRedirect
This commit is contained in:
parent
21aa82e064
commit
6ff3389f6e
|
@ -224,14 +224,26 @@ class System extends BaseObject
|
||||||
* If you want to route relative to the current Friendica base, use App->internalRedirect()
|
* If you want to route relative to the current Friendica base, use App->internalRedirect()
|
||||||
*
|
*
|
||||||
* @param string $url The new Location to redirect
|
* @param string $url The new Location to redirect
|
||||||
|
* @param int $code The redirection code, which is used (Default is 302)
|
||||||
|
*
|
||||||
* @throws InternalServerErrorException If the URL is not fully qualified
|
* @throws InternalServerErrorException If the URL is not fully qualified
|
||||||
*/
|
*/
|
||||||
public static function externalRedirect($url)
|
public static function externalRedirect($url, $code = 302)
|
||||||
{
|
{
|
||||||
if (empty(parse_url($url, PHP_URL_SCHEME))) {
|
if (empty(parse_url($url, PHP_URL_SCHEME))) {
|
||||||
throw new InternalServerErrorException("'$url' is not a fully qualified URL, please use App->internalRedirect() instead");
|
throw new InternalServerErrorException("'$url' is not a fully qualified URL, please use App->internalRedirect() instead");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch ($code) {
|
||||||
|
case 302:
|
||||||
|
// this is the default code for a REDIRECT
|
||||||
|
// We don't need a extra header here
|
||||||
|
break;
|
||||||
|
case 301:
|
||||||
|
header('HTTP/1.1 301 Moved Permanently');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
header("Location: $url");
|
header("Location: $url");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Friendica\Module\Diaspora;
|
||||||
|
|
||||||
use Friendica\BaseModule;
|
use Friendica\BaseModule;
|
||||||
use Friendica\Core\Protocol;
|
use Friendica\Core\Protocol;
|
||||||
|
use Friendica\Core\System;
|
||||||
use Friendica\Model\Item;
|
use Friendica\Model\Item;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
|
@ -44,7 +45,7 @@ class Fetch extends BaseModule
|
||||||
|
|
||||||
if (Strings::normaliseLink($host) != Strings::normaliseLink($app->getBaseURL())) {
|
if (Strings::normaliseLink($host) != Strings::normaliseLink($app->getBaseURL())) {
|
||||||
$location = $host . "/fetch/" . $app->argv[1] . "/" . urlencode($guid);
|
$location = $host . "/fetch/" . $app->argv[1] . "/" . urlencode($guid);
|
||||||
$app->redirect($location);
|
System::externalRedirect($location, 301);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue