Ayemae / Grawlix-Webcomic-CMS

PHP-based webcomic CMS
22 stars 5 forks source link

Send 404 headers when displaying 404 error pages #1

Closed eishiya closed 3 years ago

eishiya commented 3 years ago

Presently, Grawlix sends HTTP status code 200 OK even when displaying error pages. With this PR, it sends 404 headers whenever:

All the other page content is displayed as before, all that's different is the header.

I also commented out a check that sends a 200 header because it was never true anyway.

The 404 header (mostly) is sent in one place: GrlxPage2::buildPage(). The scenarios that cause it just set a statusCode property that's checked in that method. This means that it should be smooth to add this to any other error pages I may have missed, as well as adding headers for other error codes if the need arises. The one exception is the 404 sent when page info cannot be found. I had to send it there as well because afterwards PHP just die()s.

The header is not sent in any case where Grawlix has no explicit error handling, such as requests to /comic/non-numeric-ID (Grawlix just shows the base page template with no content in these cases). These errors are very unlikely, but probably worth looking into handling at a later date.