mirror of
https://github.com/friendica/friendica
synced 2025-04-19 10:30:10 +00:00
Unified output via the "httpExit" function
This commit is contained in:
parent
d15023fe4b
commit
4a22034be6
16 changed files with 69 additions and 70 deletions
|
@ -22,6 +22,8 @@
|
|||
namespace Friendica\Module\DFRN;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Protocol\OStatus;
|
||||
|
||||
/**
|
||||
|
@ -31,9 +33,7 @@ class Poll extends BaseModule
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
header("Content-type: application/atom+xml");
|
||||
$last_update = $_GET['last_update'] ?? '';
|
||||
echo OStatus::feed($this->parameters['nickname'], $last_update, 10);
|
||||
exit();
|
||||
$last_update = $request['last_update'] ?? '';
|
||||
System::httpExit(OStatus::feed($this->parameters['nickname'], $last_update, 10), Response::TYPE_ATOM);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ use Friendica\DI;
|
|||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Protocol\Diaspora;
|
||||
use Friendica\Util\Strings;
|
||||
|
@ -84,9 +85,6 @@ class Fetch extends BaseModule
|
|||
$xml = Diaspora::buildPostXml($status["type"], $status["message"]);
|
||||
|
||||
// Send the envelope
|
||||
header("Content-Type: application/magic-envelope+xml; charset=utf-8");
|
||||
echo Diaspora::buildMagicEnvelope($xml, $user);
|
||||
|
||||
exit();
|
||||
System::httpExit(Diaspora::buildMagicEnvelope($xml, $user), Response::TYPE_XML, 'application/magic-envelope+xml');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Protocol\Feed as ProtocolFeed;
|
||||
|
||||
|
@ -43,10 +44,8 @@ class Feed extends BaseModule
|
|||
{
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
$a = DI::app();
|
||||
|
||||
$last_update = $_GET['last_update'] ?? '';
|
||||
$nocache = !empty($_GET['nocache']) && local_user();
|
||||
$last_update = $request['last_update'] ?? '';
|
||||
$nocache = !empty($request['nocache']) && local_user();
|
||||
|
||||
$type = null;
|
||||
// @TODO: Replace with parameter from router
|
||||
|
@ -67,8 +66,6 @@ class Feed extends BaseModule
|
|||
$type = 'posts';
|
||||
}
|
||||
|
||||
header("Content-type: application/atom+xml; charset=utf-8");
|
||||
echo ProtocolFeed::atom($this->parameters['nickname'], $last_update, 10, $type, $nocache, true);
|
||||
exit();
|
||||
System::httpExit(ProtocolFeed::atom($this->parameters['nickname'], $last_update, 10, $type, $nocache, true), Response::TYPE_ATOM);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -291,9 +291,7 @@ class Ping extends BaseModule
|
|||
|
||||
if (isset($_GET['callback'])) {
|
||||
// JSONP support
|
||||
header("Content-type: application/javascript");
|
||||
echo $_GET['callback'] . '(' . json_encode(['result' => $data]) . ')';
|
||||
exit;
|
||||
System::httpExit($_GET['callback'] . '(' . json_encode(['result' => $data]) . ')', Response::TYPE_BLANK, 'application/javascript');
|
||||
} else {
|
||||
System::jsonExit(['result' => $data]);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace Friendica\Module;
|
|||
use DOMDocument;
|
||||
use DOMElement;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
|
@ -38,8 +39,6 @@ class OpenSearch extends BaseModule
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
header('Content-type: application/opensearchdescription+xml');
|
||||
|
||||
$hostname = DI::baseUrl()->getHostname();
|
||||
$baseUrl = DI::baseUrl()->get();
|
||||
|
||||
|
@ -85,8 +84,6 @@ class OpenSearch extends BaseModule
|
|||
'template' => "$baseUrl/opensearch",
|
||||
]);
|
||||
|
||||
echo $xml->saveXML();
|
||||
|
||||
exit();
|
||||
System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/opensearchdescription+xml');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Network\HTTPException\BadRequestException;
|
||||
|
@ -48,9 +49,7 @@ class PublicRSAKey extends BaseModule
|
|||
|
||||
Crypto::pemToMe($user['spubkey'], $modulus, $exponent);
|
||||
|
||||
header('Content-type: application/magic-public-key');
|
||||
echo 'RSA' . '.' . Strings::base64UrlEncode($modulus, true) . '.' . Strings::base64UrlEncode($exponent, true);
|
||||
|
||||
exit();
|
||||
$content = 'RSA' . '.' . Strings::base64UrlEncode($modulus, true) . '.' . Strings::base64UrlEncode($exponent, true);
|
||||
System::httpExit($content, Response::TYPE_BLANK, 'application/magic-public-key');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
|
@ -33,10 +34,8 @@ class ReallySimpleDiscovery extends BaseModule
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
header('Content-Type: text/xml');
|
||||
|
||||
$xml = null;
|
||||
echo XML::fromArray([
|
||||
$content = XML::fromArray([
|
||||
'rsd' => [
|
||||
'@attributes' => [
|
||||
'version' => '1.0',
|
||||
|
@ -69,6 +68,6 @@ class ReallySimpleDiscovery extends BaseModule
|
|||
],
|
||||
],
|
||||
], $xml);
|
||||
exit();
|
||||
System::httpExit($content, Response::TYPE_XML);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ class Response implements ICanCreateResponses
|
|||
|
||||
switch ($type) {
|
||||
case static::TYPE_HTML:
|
||||
$content_type = $content_type ?? 'text/html';
|
||||
$content_type = $content_type ?? 'text/html; charset=utf-8';
|
||||
break;
|
||||
case static::TYPE_JSON:
|
||||
$content_type = $content_type ?? 'application/json';
|
||||
|
|
|
@ -74,7 +74,7 @@ class HTTPException
|
|||
$content = Renderer::replaceMacros($tpl, self::getVars($e));
|
||||
}
|
||||
|
||||
System::httpExit($e->getCode(), $e->getDescription(), $content);
|
||||
System::httpError($e->getCode(), $e->getDescription(), $content);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,7 +23,9 @@ namespace Friendica\Module\WellKnown;
|
|||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Protocol\Salmon;
|
||||
use Friendica\Util\Crypto;
|
||||
|
||||
|
@ -37,8 +39,6 @@ class HostMeta extends BaseModule
|
|||
{
|
||||
$config = DI::config();
|
||||
|
||||
header('Content-type: text/xml');
|
||||
|
||||
if (!$config->get('system', 'site_pubkey', false)) {
|
||||
$res = Crypto::newKeypair(1024);
|
||||
|
||||
|
@ -47,13 +47,13 @@ class HostMeta extends BaseModule
|
|||
}
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('xrd_host.tpl');
|
||||
echo Renderer::replaceMacros($tpl, [
|
||||
$content = Renderer::replaceMacros($tpl, [
|
||||
'$zhost' => DI::baseUrl()->getHostname(),
|
||||
'$zroot' => DI::baseUrl()->get(),
|
||||
'$domain' => DI::baseUrl()->get(),
|
||||
'$bigkey' => Salmon::salmonKey($config->get('system', 'site_pubkey'))
|
||||
]);
|
||||
|
||||
exit();
|
||||
System::httpExit($content, Response::TYPE_XML);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,9 +46,9 @@ class Xrd extends BaseModule
|
|||
|
||||
$uri = urldecode(trim($_GET['uri']));
|
||||
if (strpos($_SERVER['HTTP_ACCEPT'] ?? '', 'application/jrd+json') !== false) {
|
||||
$mode = 'json';
|
||||
$mode = Response::TYPE_JSON;
|
||||
} else {
|
||||
$mode = 'xml';
|
||||
$mode = Response::TYPE_XML;
|
||||
}
|
||||
} else {
|
||||
if (empty($_GET['resource'])) {
|
||||
|
@ -57,9 +57,9 @@ class Xrd extends BaseModule
|
|||
|
||||
$uri = urldecode(trim($_GET['resource']));
|
||||
if (strpos($_SERVER['HTTP_ACCEPT'] ?? '', 'application/xrd+xml') !== false) {
|
||||
$mode = 'xml';
|
||||
$mode = Response::TYPE_XML;
|
||||
} else {
|
||||
$mode = 'json';
|
||||
$mode = Response::TYPE_JSON;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ class Xrd extends BaseModule
|
|||
$avatar = ['type' => 'image/jpeg'];
|
||||
}
|
||||
|
||||
if ($mode == 'xml') {
|
||||
if ($mode == Response::TYPE_JSON) {
|
||||
self::printXML($alias, DI::baseUrl()->get(), $user, $owner, $avatar);
|
||||
} else {
|
||||
self::printJSON($alias, DI::baseUrl()->get(), $owner, $avatar);
|
||||
|
@ -238,9 +238,6 @@ class Xrd extends BaseModule
|
|||
{
|
||||
$salmon_key = Salmon::salmonKey($owner['spubkey']);
|
||||
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Content-type: text/xml');
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('xrd_person.tpl');
|
||||
|
||||
$o = Renderer::replaceMacros($tpl, [
|
||||
|
@ -263,7 +260,8 @@ class Xrd extends BaseModule
|
|||
$arr = ['user' => $user, 'xml' => $o];
|
||||
Hook::callAll('personal_xrd', $arr);
|
||||
|
||||
echo $arr['xml'];
|
||||
exit();
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
|
||||
System::httpExit($arr['xml'], Response::TYPE_XML);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue