Move dependency-less Page->exit to Core\System::echoResponse
- The method doesn't actually exit - Fix a bug with header handling in System::echoResponse with numerical key header strings - Adding a full-string header with ICanCreateResponses->setHeader was resulting in a wrong header named after the numerical key
This commit is contained in:
parent
dd7bea4bd1
commit
94e3dde2e3
|
@ -716,7 +716,7 @@ class App
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->logger->debug('Request processed sucessfully', ['response' => $response->getStatusCode(), 'address' => $_SERVER['REMOTE_ADDR'] ?? '', 'request' => $requeststring, 'referer' => $_SERVER['HTTP_REFERER'] ?? '', 'user-agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
|
$this->logger->debug('Request processed sucessfully', ['response' => $response->getStatusCode(), 'address' => $_SERVER['REMOTE_ADDR'] ?? '', 'request' => $requeststring, 'referer' => $_SERVER['HTTP_REFERER'] ?? '', 'user-agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
|
||||||
$page->exit($response);
|
System::echoResponse($response);
|
||||||
} catch (HTTPException $e) {
|
} catch (HTTPException $e) {
|
||||||
$this->logger->debug('Request processed with exception', ['response' => $e->getCode(), 'address' => $_SERVER['REMOTE_ADDR'] ?? '', 'request' => $requeststring, 'referer' => $_SERVER['HTTP_REFERER'] ?? '', 'user-agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
|
$this->logger->debug('Request processed with exception', ['response' => $e->getCode(), 'address' => $_SERVER['REMOTE_ADDR'] ?? '', 'request' => $requeststring, 'referer' => $_SERVER['HTTP_REFERER'] ?? '', 'user-agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
|
||||||
$httpException->rawContent($e);
|
$httpException->rawContent($e);
|
||||||
|
|
|
@ -401,36 +401,6 @@ class Page implements ArrayAccess
|
||||||
$this->footerScripts[] = trim($url, '/');
|
$this->footerScripts[] = trim($url, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Directly exit with the current response (include setting all headers)
|
|
||||||
*
|
|
||||||
* @param ResponseInterface $response
|
|
||||||
*/
|
|
||||||
public function exit(ResponseInterface $response)
|
|
||||||
{
|
|
||||||
header(sprintf("HTTP/%s %s %s",
|
|
||||||
$response->getProtocolVersion(),
|
|
||||||
$response->getStatusCode(),
|
|
||||||
$response->getReasonPhrase())
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($response->getHeaders() as $key => $header) {
|
|
||||||
if (is_array($header)) {
|
|
||||||
$header_str = implode(',', $header);
|
|
||||||
} else {
|
|
||||||
$header_str = $header;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($key)) {
|
|
||||||
header($header_str);
|
|
||||||
} else {
|
|
||||||
header("$key: $header_str");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
echo $response->getBody();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the creation of the current page and prints it to the screen
|
* Executes the creation of the current page and prints it to the screen
|
||||||
*
|
*
|
||||||
|
|
|
@ -32,6 +32,7 @@ use Friendica\Network\HTTPException\MovedPermanentlyException;
|
||||||
use Friendica\Network\HTTPException\TemporaryRedirectException;
|
use Friendica\Network\HTTPException\TemporaryRedirectException;
|
||||||
use Friendica\Util\BasePath;
|
use Friendica\Util\BasePath;
|
||||||
use Friendica\Util\XML;
|
use Friendica\Util\XML;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -274,6 +275,36 @@ class System
|
||||||
return implode(', ', $callstack2);
|
return implode(', ', $callstack2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display current response, including setting all headers
|
||||||
|
*
|
||||||
|
* @param ResponseInterface $response
|
||||||
|
*/
|
||||||
|
public static function echoResponse(ResponseInterface $response)
|
||||||
|
{
|
||||||
|
header(sprintf("HTTP/%s %s %s",
|
||||||
|
$response->getProtocolVersion(),
|
||||||
|
$response->getStatusCode(),
|
||||||
|
$response->getReasonPhrase())
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($response->getHeaders() as $key => $header) {
|
||||||
|
if (is_array($header)) {
|
||||||
|
$header_str = implode(',', $header);
|
||||||
|
} else {
|
||||||
|
$header_str = $header;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_int($key)) {
|
||||||
|
header($header_str);
|
||||||
|
} else {
|
||||||
|
header("$key: $header_str");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $response->getBody();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic XML return
|
* Generic XML return
|
||||||
* Outputs a basic dfrn XML status structure to STDOUT, with a <status> variable
|
* Outputs a basic dfrn XML status structure to STDOUT, with a <status> variable
|
||||||
|
@ -297,7 +328,7 @@ class System
|
||||||
|
|
||||||
DI::apiResponse()->setType(Response::TYPE_XML);
|
DI::apiResponse()->setType(Response::TYPE_XML);
|
||||||
DI::apiResponse()->addContent(XML::fromArray(['result' => $result]));
|
DI::apiResponse()->addContent(XML::fromArray(['result' => $result]));
|
||||||
DI::page()->exit(DI::apiResponse()->generate());
|
self::echoResponse(DI::apiResponse()->generate());
|
||||||
|
|
||||||
self::exit();
|
self::exit();
|
||||||
}
|
}
|
||||||
|
@ -317,7 +348,7 @@ class System
|
||||||
}
|
}
|
||||||
DI::apiResponse()->setStatus($httpCode, $message);
|
DI::apiResponse()->setStatus($httpCode, $message);
|
||||||
DI::apiResponse()->addContent($content);
|
DI::apiResponse()->addContent($content);
|
||||||
DI::page()->exit(DI::apiResponse()->generate());
|
self::echoResponse(DI::apiResponse()->generate());
|
||||||
|
|
||||||
self::exit();
|
self::exit();
|
||||||
}
|
}
|
||||||
|
@ -334,7 +365,7 @@ class System
|
||||||
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()->setType($type, $content_type);
|
||||||
DI::apiResponse()->addContent($content);
|
DI::apiResponse()->addContent($content);
|
||||||
DI::page()->exit(DI::apiResponse()->generate());
|
self::echoResponse(DI::apiResponse()->generate());
|
||||||
|
|
||||||
self::exit();
|
self::exit();
|
||||||
}
|
}
|
||||||
|
@ -363,7 +394,7 @@ class System
|
||||||
public static function jsonExit($content, $content_type = 'application/json', int $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) {
|
public static function jsonExit($content, $content_type = 'application/json', int $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) {
|
||||||
DI::apiResponse()->setType(Response::TYPE_JSON, $content_type);
|
DI::apiResponse()->setType(Response::TYPE_JSON, $content_type);
|
||||||
DI::apiResponse()->addContent(json_encode($content, $options));
|
DI::apiResponse()->addContent(json_encode($content, $options));
|
||||||
DI::page()->exit(DI::apiResponse()->generate());
|
self::echoResponse(DI::apiResponse()->generate());
|
||||||
|
|
||||||
self::exit();
|
self::exit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,7 @@ class Upload extends \Friendica\BaseModule
|
||||||
$this->response->addContent($message);
|
$this->response->addContent($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->page->exit($this->response->generate());
|
System::echoResponse($this->response->generate());
|
||||||
System::exit();
|
System::exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,7 +207,7 @@ class Upload extends \Friendica\BaseModule
|
||||||
$this->response->addContent($message);
|
$this->response->addContent($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->page->exit($this->response->generate());
|
System::echoResponse($this->response->generate());
|
||||||
System::exit();
|
System::exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user