Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reset sapi response code #964

Merged
merged 4 commits into from
Aug 11, 2024
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: 3 additions & 0 deletions frankenphp.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@ int frankenphp_update_server_context(
ctx = (frankenphp_server_context *)SG(server_context);
}

// It is not reset by zend engine, set it to 200.
SG(sapi_headers).http_response_code = 200;

ctx->main_request = main_request;
ctx->current_request = current_request;

Expand Down
6 changes: 6 additions & 0 deletions frankenphp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ func testResponseHeaders(t *testing.T, opts *testOptions) {
resp := w.Result()
body, _ := io.ReadAll(resp.Body)

if i%3 != 0 {
assert.Equal(t, i+100, resp.StatusCode)
} else {
assert.Equal(t, 200, resp.StatusCode)
}

assert.Contains(t, string(body), "'X-Powered-By' => 'PH")
assert.Contains(t, string(body), "'Foo' => 'bar',")
assert.Contains(t, string(body), "'Foo2' => 'bar2',")
Expand Down
6 changes: 4 additions & 2 deletions testdata/response-headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
header('Foo2: bar2');
header('Invalid');
header('I: ' . ($_GET['i'] ?? 'i not set'));
http_response_code(201);

if ($_GET['i'] % 3) {
http_response_code($_GET['i'] + 100);
}

var_export(apache_response_headers());
};
Loading