From fadc8738c0e42ace79482655a2fddad9a8733512 Mon Sep 17 00:00:00 2001 From: Petr Shumilov Date: Wed, 25 Mar 2026 16:42:19 +0300 Subject: [PATCH 1/3] Align semantics of headers_list with baseline kphp Signed-off-by: Petr Shumilov --- runtime-light/server/http/http-server-state.h | 15 ++++++++++++++- runtime-light/server/http/init-functions.cpp | 4 ---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/runtime-light/server/http/http-server-state.h b/runtime-light/server/http/http-server-state.h index 261a35dce4..551a84d29d 100644 --- a/runtime-light/server/http/http-server-state.h +++ b/runtime-light/server/http/http-server-state.h @@ -46,6 +46,7 @@ inline constexpr std::string_view CONTENT_LENGTH = "content-length"; inline constexpr std::string_view AUTHORIZATION = "authorization"; inline constexpr std::string_view ACCEPT_ENCODING = "accept-encoding"; inline constexpr std::string_view CONTENT_ENCODING = "content-encoding"; +inline constexpr std::string_view SERVER = "server"; } // namespace headers @@ -73,8 +74,20 @@ struct HttpServerInstanceState final : private vk::not_copyable { kphp::stl::multimap, kphp::stl::string, kphp::memory::script_allocator> headers_; + // Setup default headers + void headers_init() noexcept { + constexpr std::string_view DEFAULT_SERVER_NAME = "nginx/0.3.33"; + constexpr std::string_view DEFAULT_CONTENT_TYPE = "text/html; charset=windows-1251"; + // add 'server' header + add_header(kphp::http::headers::SERVER, DEFAULT_SERVER_NAME, false); + // add 'content-type' header + add_header(kphp::http::headers::CONTENT_TYPE, DEFAULT_CONTENT_TYPE, false); + } + public: - HttpServerInstanceState() noexcept = default; + HttpServerInstanceState() noexcept { + headers_init(); + } const auto& headers() const noexcept { return headers_; diff --git a/runtime-light/server/http/init-functions.cpp b/runtime-light/server/http/init-functions.cpp index eda7340671..4344e67870 100644 --- a/runtime-light/server/http/init-functions.cpp +++ b/runtime-light/server/http/init-functions.cpp @@ -58,7 +58,6 @@ constexpr std::string_view CONNECTION_CLOSE = "close"; constexpr std::string_view CONNECTION_KEEP_ALIVE = "keep-alive"; constexpr std::string_view ENCODING_GZIP = "gzip"; constexpr std::string_view ENCODING_DEFLATE = "deflate"; -constexpr std::string_view CONTENT_TYPE_TEXT_WIN1251 = "text/html; charset=windows-1251"; constexpr std::string_view CONTENT_TYPE_APP_FORM_URLENCODED = "application/x-www-form-urlencoded"; constexpr std::string_view CONTENT_TYPE_MULTIPART_FORM_DATA = "multipart/form-data"; @@ -351,10 +350,7 @@ void init_server(kphp::component::stream&& request_stream, kphp::stl::vector Date: Wed, 25 Mar 2026 16:43:05 +0300 Subject: [PATCH 2/3] Enable and refactor test Signed-off-by: Petr Shumilov --- tests/phpt/pk/015_header.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/phpt/pk/015_header.php b/tests/phpt/pk/015_header.php index b3627a1c3c..4298bec84c 100644 --- a/tests/phpt/pk/015_header.php +++ b/tests/phpt/pk/015_header.php @@ -1,4 +1,4 @@ -@ok k2_skip +@ok &$v) { + $v = strtolower($v); +} +sort($x); + #ifndef KPHP // not working in console php $x = [ - 'Server: nginx/0.3.33', - 'Date: haha, date in tests', - 'Content-Type: text/html; charset=windows-1251', - 'X-TEST-1: value2', - 'X-TEST-2: value1', - 'X-TEST-2: value2', - 'X-TEST-3: value3', - 'Set-Cookie: test-cookie=blabla' + 'content-type: text/html; charset=windows-1251', + 'date: haha, date in tests', + 'server: nginx/0.3.33', + 'set-cookie: test-cookie=blabla', + 'x-test-1: value2', + 'x-test-2: value1', + 'x-test-2: value2', + 'x-test-3: value3' ]; #endif From f32a6c515af469ad0fc4ccc1b4d7af982a570637 Mon Sep 17 00:00:00 2001 From: Alexander Polyakov Date: Wed, 25 Mar 2026 19:08:30 +0300 Subject: [PATCH 3/3] small changes --- runtime-light/server/http/http-server-state.h | 16 ++-------------- runtime-light/server/http/init-functions.cpp | 2 +- runtime-light/state/instance-state.cpp | 10 ++++++++++ 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/runtime-light/server/http/http-server-state.h b/runtime-light/server/http/http-server-state.h index 551a84d29d..ead649da69 100644 --- a/runtime-light/server/http/http-server-state.h +++ b/runtime-light/server/http/http-server-state.h @@ -38,6 +38,7 @@ namespace headers { inline constexpr std::string_view HOST = "host"; inline constexpr std::string_view COOKIE = "cookie"; +inline constexpr std::string_view SERVER = "server"; inline constexpr std::string_view LOCATION = "location"; inline constexpr std::string_view SET_COOKIE = "set-cookie"; inline constexpr std::string_view CONNECTION = "connection"; @@ -46,7 +47,6 @@ inline constexpr std::string_view CONTENT_LENGTH = "content-length"; inline constexpr std::string_view AUTHORIZATION = "authorization"; inline constexpr std::string_view ACCEPT_ENCODING = "accept-encoding"; inline constexpr std::string_view CONTENT_ENCODING = "content-encoding"; -inline constexpr std::string_view SERVER = "server"; } // namespace headers @@ -74,20 +74,8 @@ struct HttpServerInstanceState final : private vk::not_copyable { kphp::stl::multimap, kphp::stl::string, kphp::memory::script_allocator> headers_; - // Setup default headers - void headers_init() noexcept { - constexpr std::string_view DEFAULT_SERVER_NAME = "nginx/0.3.33"; - constexpr std::string_view DEFAULT_CONTENT_TYPE = "text/html; charset=windows-1251"; - // add 'server' header - add_header(kphp::http::headers::SERVER, DEFAULT_SERVER_NAME, false); - // add 'content-type' header - add_header(kphp::http::headers::CONTENT_TYPE, DEFAULT_CONTENT_TYPE, false); - } - public: - HttpServerInstanceState() noexcept { - headers_init(); - } + HttpServerInstanceState() noexcept = default; const auto& headers() const noexcept { return headers_; diff --git a/runtime-light/server/http/init-functions.cpp b/runtime-light/server/http/init-functions.cpp index 4344e67870..a444833d6f 100644 --- a/runtime-light/server/http/init-functions.cpp +++ b/runtime-light/server/http/init-functions.cpp @@ -349,12 +349,12 @@ void init_server(kphp::component::stream&& request_stream, kphp::stl::vector {}, " "server port -> {}, " diff --git a/runtime-light/state/instance-state.cpp b/runtime-light/state/instance-state.cpp index 1e97fea083..4b27210266 100644 --- a/runtime-light/state/instance-state.cpp +++ b/runtime-light/state/instance-state.cpp @@ -21,6 +21,7 @@ #include "runtime-light/coroutine/task.h" #include "runtime-light/k2-platform/k2-api.h" #include "runtime-light/server/cli/init-functions.h" +#include "runtime-light/server/http/http-server-state.h" #include "runtime-light/server/http/init-functions.h" #include "runtime-light/server/rpc/init-functions.h" #include "runtime-light/state/component-state.h" @@ -150,6 +151,15 @@ kphp::coro::task<> InstanceState::run_instance_prologue() noexcept { superglobals.v$d$PHP_SAPI = string{sapi_name.data(), sapi_name.size()}; } + if constexpr (kind == image_kind::cli || kind == image_kind::server) { + // TODO set these headers in CLI and HTTP modes only + static constexpr std::string_view DEFAULT_SERVER_NAME{"nginx/0.3.33"}; + static constexpr std::string_view DEFAULT_CONTENT_TYPE{"text/html; charset=windows-1251"}; + + http_server_instance_state.add_header(kphp::http::headers::SERVER, DEFAULT_SERVER_NAME, false); + http_server_instance_state.add_header(kphp::http::headers::CONTENT_TYPE, DEFAULT_CONTENT_TYPE, false); + } + // specific initialization if constexpr (kind == image_kind::cli) { co_await init_cli_instance();