Skip to content
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
1 change: 1 addition & 0 deletions runtime-light/server/http/http-server-state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 1 addition & 5 deletions runtime-light/server/http/init-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -350,15 +349,12 @@ void init_server(kphp::component::stream&& request_stream, kphp::stl::vector<std

// ==================================
// prepare some response headers

// add content-type header
auto& static_SB{RuntimeContext::get().static_SB};
static_SB.clean() << headers::CONTENT_TYPE.data() << ": " << CONTENT_TYPE_TEXT_WIN1251.data();
kphp::http::header({static_SB.c_str(), static_SB.size()}, true, status::NO_STATUS);
// add connection kind header
const auto connection_kind{http_server_instance_st.connection_kind == connection_kind::keep_alive ? CONNECTION_KEEP_ALIVE : CONNECTION_CLOSE};
static_SB.clean() << headers::CONNECTION.data() << ": " << connection_kind.data();
kphp::http::header({static_SB.c_str(), static_SB.size()}, true, status::NO_STATUS);

kphp::log::info("http server initialized with: "
"server addr -> {}, "
"server port -> {}, "
Expand Down
10 changes: 10 additions & 0 deletions runtime-light/state/instance-state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down
23 changes: 14 additions & 9 deletions tests/phpt/pk/015_header.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@ok k2_skip
@ok
<?php

header('X-TEST-1: value1');
Expand All @@ -11,18 +11,23 @@
header('Date: haha, date in tests');
setcookie('test-cookie', 'blabla');
$x = headers_list();
foreach ($x as $_ => &$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

Expand Down
Loading