Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config.default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ error_page_dir=page/_error
router_file=router.php
router_class=AppRouter
redirect_response_code=307
default_content_type=application/json
default_content_type=text/html

[view]
component_directory=page/_component
Expand All @@ -29,6 +29,7 @@ partial_directory=page/_partial
log_all_requests=true
log_static_requests=false
log_404_to_error_log=false
log_not_modified=false
log_redirects=false
debug_to_javascript=true
stderr_level=ERROR
Expand Down
25 changes: 22 additions & 3 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
use GT\Http\RequestFactory;
use GT\Http\Response;
use GT\Http\Stream;
use GT\Http\StatusCode;
use GT\Csrf\HTMLDocumentProtector;
use GT\ProtectedGlobal\Protection;
use Psr\Http\Message\ServerRequestInterface;

Expand Down Expand Up @@ -186,11 +188,16 @@ private function handleThrowable(Throwable $throwable):?Response {
return null;
}

$this->logError($throwable);
$errorStatus = $throwable instanceof ResponseStatusException
? $throwable->getHttpCode()
: 500;

if($errorStatus === StatusCode::NOT_MODIFIED) {
return new Response(StatusCode::NOT_MODIFIED, request: $this->request);
}

$this->logError($throwable);

$this->dispatcher = $this->dispatcherFactory->create(
$this->config,
$this->request,
Expand Down Expand Up @@ -494,7 +501,7 @@ private function buildLogContext(
string $remoteAddress = "",
):array {
$postArray = is_array($postBody)
? $postBody
? $this->filterLoggedPostBody($postBody)
: [];

$context = [
Expand Down Expand Up @@ -555,8 +562,20 @@ private function shouldLogRequest(Response $response):bool {
if($statusCode === 404) {
return false;
}
if($statusCode === StatusCode::NOT_MODIFIED) {
return $this->config->getBool("logger.log_not_modified");
}

return $statusCode < 300 || $statusCode >= 400;
return true;
}

/**
* @param array<string, mixed> $postBody
* @return array<string, mixed>
*/
private function filterLoggedPostBody(array $postBody):array {
unset($postBody[HTMLDocumentProtector::TOKEN_NAME]);
return $postBody;
}

/** @param array<string, mixed> $context */
Expand Down
4 changes: 4 additions & 0 deletions src/Dispatch/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ public function generateErrorResponse(Throwable $throwable):Response {
$errorStatusCode = $throwable->getHttpCode();
}

if($errorStatusCode === StatusCode::NOT_MODIFIED) {
return $this->response->withStatus(StatusCode::NOT_MODIFIED);
}

if(!$this->viewAssembly->containsDistinctFile()) {
Log::warning(
"Error page template not found for HTTP " . $errorStatusCode,
Expand Down
Loading
Loading