Skip to content

Commit f7d353d

Browse files
committed
small changes
1 parent c79f50c commit f7d353d

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

runtime-light/server/http/http-server-state.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace headers {
3838

3939
inline constexpr std::string_view HOST = "host";
4040
inline constexpr std::string_view COOKIE = "cookie";
41+
inline constexpr std::string_view SERVER = "server";
4142
inline constexpr std::string_view LOCATION = "location";
4243
inline constexpr std::string_view SET_COOKIE = "set-cookie";
4344
inline constexpr std::string_view CONNECTION = "connection";
@@ -46,7 +47,6 @@ inline constexpr std::string_view CONTENT_LENGTH = "content-length";
4647
inline constexpr std::string_view AUTHORIZATION = "authorization";
4748
inline constexpr std::string_view ACCEPT_ENCODING = "accept-encoding";
4849
inline constexpr std::string_view CONTENT_ENCODING = "content-encoding";
49-
inline constexpr std::string_view SERVER = "server";
5050

5151
} // namespace headers
5252

@@ -74,20 +74,8 @@ struct HttpServerInstanceState final : private vk::not_copyable {
7474
kphp::stl::multimap<kphp::stl::string<kphp::memory::script_allocator>, kphp::stl::string<kphp::memory::script_allocator>, kphp::memory::script_allocator>
7575
headers_;
7676

77-
// Setup default headers
78-
void headers_init() noexcept {
79-
constexpr std::string_view DEFAULT_SERVER_NAME = "nginx/0.3.33";
80-
constexpr std::string_view DEFAULT_CONTENT_TYPE = "text/html; charset=windows-1251";
81-
// add 'server' header
82-
add_header(kphp::http::headers::SERVER, DEFAULT_SERVER_NAME, false);
83-
// add 'content-type' header
84-
add_header(kphp::http::headers::CONTENT_TYPE, DEFAULT_CONTENT_TYPE, false);
85-
}
86-
8777
public:
88-
HttpServerInstanceState() noexcept {
89-
headers_init();
90-
}
78+
HttpServerInstanceState() noexcept = default;
9179

9280
const auto& headers() const noexcept {
9381
return headers_;

runtime-light/server/http/init-functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,12 @@ void init_server(kphp::component::stream&& request_stream, kphp::stl::vector<std
349349

350350
// ==================================
351351
// prepare some response headers
352-
353352
auto& static_SB{RuntimeContext::get().static_SB};
354353
// add connection kind header
355354
const auto connection_kind{http_server_instance_st.connection_kind == connection_kind::keep_alive ? CONNECTION_KEEP_ALIVE : CONNECTION_CLOSE};
356355
static_SB.clean() << headers::CONNECTION.data() << ": " << connection_kind.data();
357356
kphp::http::header({static_SB.c_str(), static_SB.size()}, true, status::NO_STATUS);
357+
358358
kphp::log::info("http server initialized with: "
359359
"server addr -> {}, "
360360
"server port -> {}, "

runtime-light/state/instance-state.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "runtime-light/coroutine/task.h"
2222
#include "runtime-light/k2-platform/k2-api.h"
2323
#include "runtime-light/server/cli/init-functions.h"
24+
#include "runtime-light/server/http/http-server-state.h"
2425
#include "runtime-light/server/http/init-functions.h"
2526
#include "runtime-light/server/rpc/init-functions.h"
2627
#include "runtime-light/state/component-state.h"
@@ -150,6 +151,15 @@ kphp::coro::task<> InstanceState::run_instance_prologue() noexcept {
150151
superglobals.v$d$PHP_SAPI = string{sapi_name.data(), sapi_name.size()};
151152
}
152153

154+
if constexpr (kind == image_kind::cli || kind == image_kind::server) {
155+
// TODO set these headers in CLI and HTTP modes only
156+
static constexpr std::string_view DEFAULT_SERVER_NAME{"nginx/0.3.33"};
157+
static constexpr std::string_view DEFAULT_CONTENT_TYPE{"text/html; charset=windows-1251"};
158+
159+
http_server_instance_state.add_header(kphp::http::headers::SERVER, DEFAULT_SERVER_NAME, false);
160+
http_server_instance_state.add_header(kphp::http::headers::CONTENT_TYPE, DEFAULT_CONTENT_TYPE, false);
161+
}
162+
153163
// specific initialization
154164
if constexpr (kind == image_kind::cli) {
155165
co_await init_cli_instance();

0 commit comments

Comments
 (0)