Skip to content

Conversation

@tombroucke
Copy link
Contributor

Fixes #484
WordPress sets a 404 statuscode in the WP::handle_404() method, but that got overwritten by the default status code of the Response class. We can fetch the status set by WP using http_response_code(), and pass that in to the sendHeaders() method. This will relay all status codes, but I'm assuming if WP throws a 301, we should follow that.

Tests are running fine, but this should probably be tested manually.

@retlehs
Copy link
Member

retlehs commented Oct 16, 2025

Thanks for the PR! With these changes:

❯ curl -I http://example.test/asdf
HTTP/1.1 404 Not Found 
❯ curl -I http://example.test/asdf/
HTTP/1.1 404 OK

"404 OK" probably isn't what we want?

@tombroucke
Copy link
Contributor Author

tombroucke commented Oct 16, 2025

I didn't see the response text because of HTTP/2.
If we use the setStatusCode() method, it will also update the statusText.

Copy link
Member

@retlehs retlehs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❯ curl -I http://example.test/asdf/
HTTP/1.1 404 Not Found

Thank you!

@Log1x
Copy link
Member

Log1x commented Oct 18, 2025

nice find! does

$response->setStatusCode(http_response_code());
still end up being necessary?

@tombroucke
Copy link
Contributor Author

nice find! does

$response->setStatusCode(http_response_code());

still end up being necessary?

I did some testing and I found this is no longer necessary. The status code is always set twice, the first time (line 166) is not always correct, the second time (line 237) is.

However, I did noticed that the "Poor man's wp cron" requests don't fire the send_headers action, so the status code is only set once (from line 166). We should probably add site_url('wp-cron.php') to the $except collection to have wordpress handle these requests.

$except = collect([
    admin_url(),
    wp_login_url(),
    wp_registration_url(),
    rest_url(),
    site_url('wp-cron.php'),
])->map(fn ($url) => parse_url($url, PHP_URL_PATH))->unique()->filter();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants