- This will ensure headers set in BaseModule->run will be carried in httpExit scenarios
- Deprecate httpExit() method in Core\System
}
if ($_GET["mode"] == "raw") {
- System::httpExit(substr($target->saveHTML(), 6, -8), Response::TYPE_HTML);
+ $response->withBody(Utils::streamFor($target->saveHTML()));
+ System::echoResponse($response);
+ System::exit();
}
}
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
+use Friendica\Core\System;
use Friendica\Model\User;
use Friendica\Module\Response;
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
*/
protected function rawContent(array $request = [])
{
- // echo '';
- // exit;
+ // $this->httpExit(...);
}
/**
$timestamp = microtime(true);
// "rawContent" is especially meant for technical endpoints.
- // This endpoint doesn't need any theme initialization or other comparable stuff.
+ // This endpoint doesn't need any theme initialization or
+ // templating and is expected to exit on its own if it is set.
$this->rawContent($request);
try {
return $tabs;
}
+
+ /**
+ * This function adds the content and a content-type HTTP header to the output.
+ * After finishing the process is getting killed.
+ *
+ * @param string $content
+ * @param string $type
+ * @param string|null $content_type
+ * @return void
+ * @throws HTTPException\InternalServerErrorException
+ */
+ public function httpExit(string $content, string $type = Response::TYPE_HTML, ?string $content_type = null)
+ {
+ $this->response->setType($type, $content_type);
+ $this->response->addContent($content);
+ System::echoResponse($this->response->generate());
+
+ System::exit();
+ }
}
*
* @throws InternalServerErrorException
*/
- public function setType(string $type, ?string $content_type = null): void;
+ public function setType(string $type = ICanCreateResponses::TYPE_HTML, ?string $content_type = null): void;
/**
* Sets the status and the reason for the response
use Friendica\Model\User;
use Friendica\Module\Response;
use Friendica\Network\HTTPException\FoundException;
+use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Network\HTTPException\MovedPermanentlyException;
use Friendica\Network\HTTPException\TemporaryRedirectException;
use Friendica\Util\BasePath;
* This function adds the content and a content-type HTTP header to the output.
* After finishing the process is getting killed.
*
- * @param string $content
- * @param string $type
+ * @param string $content
+ * @param string $type
* @param string|null $content_type
* @return void
+ * @throws InternalServerErrorException
+ * @deprecated since 2023.09 Use BaseModule->httpExit() instead
*/
- public static function httpExit(string $content, string $type = Response::TYPE_HTML, ?string $content_type = null) {
+ public static function httpExit(string $content, string $type = Response::TYPE_HTML, ?string $content_type = null)
+ {
DI::apiResponse()->setType($type, $content_type);
DI::apiResponse()->addContent($content);
self::echoResponse(DI::apiResponse()->generate());
if (strcmp($finish, $start) < 0 && !$noFinish) {
if ($isPreview) {
- System::httpExit($this->t('Event can not end before it has started.'));
+ $this->httpExit($this->t('Event can not end before it has started.'));
} else {
$this->sysMessages->addNotice($this->t('Event can not end before it has started.'));
$this->baseUrl->redirect($redirectOnError);
if (empty($summary) || ($start === DBA::NULL_DATETIME)) {
if ($isPreview) {
- System::httpExit($this->t('Event title and start time are required.'));
+ $this->httpExit($this->t('Event title and start time are required.'));
} else {
$this->sysMessages->addNotice($this->t('Event title and start time are required.'));
$this->baseUrl->redirect($redirectOnError);
];
if (intval($request['preview'])) {
- System::httpExit(Event::getHTML($datarray));
+ $this->httpExit(Event::getHTML($datarray));
}
$eventId = Event::store($datarray);
'$event' => $tplEvent,
]);
- System::httpExit($o);
+ $this->httpExit($o);
}
}
],
]);
- System::httpExit($o);
+ $this->httpExit($o);
}
}
}
$last_update = $request['last_update'] ?? '';
- System::httpExit(OStatus::feed($owner['nickname'], $last_update, 10) ?? '', Response::TYPE_ATOM);
+ $this->httpExit(OStatus::feed($owner['nickname'], $last_update, 10) ?? '', Response::TYPE_ATOM);
}
}
$xml = Diaspora::buildPostXml($status["type"], $status["message"]);
// Send the envelope
- System::httpExit(Diaspora::buildMagicEnvelope($xml, $user), Response::TYPE_XML, 'application/magic-envelope+xml');
+ $this->httpExit(Diaspora::buildMagicEnvelope($xml, $user), Response::TYPE_XML, 'application/magic-envelope+xml');
}
}
$feed = ProtocolFeed::atom($owner, $last_update, 10, $type);
- System::httpExit($feed, Response::TYPE_ATOM);
+ $this->httpExit($feed, Response::TYPE_ATOM);
}
}
throw new HTTPException\InternalServerErrorException($this->t('The feed for this item is unavailable.', ['uri-id' => $uriId]));
}
- System::httpExit($xml, Response::TYPE_ATOM);
+ $this->httpExit($xml, Response::TYPE_ATOM);
}
}
]);
if (empty($request['mode'])) {
- System::httpExit($output);
+ $this->httpExit($output);
}
return $output;
]);
if (empty($request['mode'])) {
- System::httpExit($output);
+ $this->httpExit($output);
}
return $output;
if (isset($_GET['callback'])) {
// JSONP support
- System::httpExit($_GET['callback'] . '(' . json_encode(['result' => $data]) . ')', Response::TYPE_BLANK, 'application/javascript');
+ $this->httpExit($_GET['callback'] . '(' . json_encode(['result' => $data]) . ')', Response::TYPE_BLANK, 'application/javascript');
} else {
System::jsonExit(['result' => $data]);
}
$this->logger->notice('Success for contact.', ['mode' => $hub_mode, 'contact' => $contact_id]);
}
- System::httpExit($hub_challenge);
+ $this->httpExit($hub_challenge);
}
}
'template' => "$baseUrl/opensearch",
]);
- System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/opensearchdescription+xml');
+ $this->httpExit($xml->saveXML(), Response::TYPE_XML, 'application/opensearchdescription+xml');
}
}
if ($format == 'json') {
System::jsonExit($arr['text']);
} else {
- System::httpExit($arr['text']);
+ $this->httpExit($arr['text']);
}
}
System::jsonExit($ret);
} else {
- System::httpExit(BBCode::embedURL($url, empty($_GET['noAttachment']), $title, $description, $_GET['tags'] ?? ''));
+ $this->httpExit(BBCode::embedURL($url, empty($_GET['noAttachment']), $title, $description, $_GET['tags'] ?? ''));
}
}
}
}
if (!empty($l)) {
- System::httpExit($o . implode(', ', $l));
+ $this->httpExit($o . implode(', ', $l));
} else {
- System::httpExit($o . $receivers);;
+ $this->httpExit($o . $receivers);;
}
}
$content = '[share]' . $item['uri'] . '[/share]';
}
- System::httpExit($content);
+ $this->httpExit($content);
}
}
throw new BadRequestException();
}
- System::httpExit(
+ $this->httpExit(
Salmon::salmonKey($user['spubkey']),
Response::TYPE_BLANK,
'application/magic-public-key'
],
],
]);
- System::httpExit($content, Response::TYPE_XML);
+ $this->httpExit($content, Response::TYPE_XML);
}
}
/**
* {@inheritDoc}
*/
- public function setType(string $type, ?string $content_type = null): void
+ public function setType(string $type = Response::TYPE_HTML, ?string $content_type = null): void
{
if (!in_array($type, static::ALLOWED_TYPES)) {
throw new InternalServerErrorException('wrong type');
],
], $xml, false, ['hm' => 'http://host-meta.net/xrd/1.0', 'mk' => 'http://salmon-protocol.org/ns/magic-key']);
- System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml');
+ $this->httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml');
}
}
]);
header('Access-Control-Allow-Origin: *');
- System::httpExit($xmlString, Response::TYPE_XML, 'application/xrd+xml');
+ $this->httpExit($xmlString, Response::TYPE_XML, 'application/xrd+xml');
}
}