Skip to content

Conversation

@kkmuffme
Copy link

@kkmuffme kkmuffme commented Oct 2, 2025

Updates the previous PR to fix 18582 to actually return the correct HTTP status code, which is sent to the browser

@kkmuffme kkmuffme changed the base branch from master to PHP-8.5 October 2, 2025 02:01
…status

Updates the previous PR to fix 18582 to actually return the correct HTTP status code, which is sent to the browser
@kkmuffme kkmuffme force-pushed the 18582-http_response_code-still-wrong-status-returned branch from 4e87e8c to 6ba0715 Compare October 2, 2025 03:59
@kkmuffme
Copy link
Author

kkmuffme commented Oct 6, 2025

@iluuu1994 sorry, not really familiar with c, could you pinpoint me to what the issue is here? The change is trivial but I can't see whats wrong with it (nor can I really run/debug it locally since I have nothing set up for it atm)

@iluuu1994
Copy link
Member

iluuu1994 commented Oct 6, 2025

In that case, you'd probably just want to return SG(sapi_headers).http_response_code and exit the function. sapi_header_op() already updates SG(sapi_headers).http_response_code for the status line.

sapi_update_response_code(sapi_extract_response_code(header_line));

I.e. something like this untested code:

diff --git a/ext/standard/head.c b/ext/standard/head.c
index 087ba6a3480..27d5dede597 100644
--- a/ext/standard/head.c
+++ b/ext/standard/head.c
@@ -384,6 +384,7 @@ PHP_FUNCTION(http_response_code)
 
 		if (SG(sapi_headers).http_status_line) {
 			php_error_docref(NULL, E_WARNING, "Calling http_response_code() after header('HTTP/...') has no effect");
+			goto return_current;
 			// If it is decided that this should have effect in the future, replace warning with
 			// efree(SG(sapi_headers).http_status_line);
 			// SG(sapi_headers).http_status_line = NULL;
@@ -401,6 +402,7 @@ PHP_FUNCTION(http_response_code)
 		RETURN_TRUE;
 	}
 
+return_current:
 	if (!SG(sapi_headers).http_response_code) {
 		RETURN_FALSE;
 	}

It's a bit unclear what the correct return value is for if (!SG(sapi_headers).http_response_code) {. Normally it's true when setting the first response code, but that's a bit misleading if it's not actually successful.

Also, you'll have to check with Jakub whether he's actually ok with this change. I won't interfere here again.

@nielsdos nielsdos requested a review from bukka October 10, 2025 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants