Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
70afdbe
add client
kekxv Dec 14, 2025
23d5dc7
add client
kekxv Dec 14, 2025
8eb6b59
test(framework): add websocket client tests and real http tests
kekxv Dec 14, 2025
96bdde1
add client
kekxv Dec 14, 2025
4812f65
feat: 增加`io_context_pool.hpp`管理io,增加client模式
kekxv Dec 14, 2025
2f58423
fix: windows macros build
kekxv Dec 14, 2025
543827b
test
kekxv Dec 14, 2025
204d0e3
test
kekxv Dec 14, 2025
b3d905a
fix: windows
kekxv Dec 14, 2025
dbaa4b7
feat: add TagInvoke.hpp
kekxv Dec 14, 2025
dc5e867
feat: add cron
kekxv Dec 14, 2025
47ad116
feat: add cron
kekxv Dec 14, 2025
0c2fdaf
readme
kekxv May 8, 2026
15858ab
完善以及测试用例
kekxv May 8, 2026
a2da17f
doc
kekxv May 8, 2026
75e9214
fix
kekxv May 9, 2026
ba926cc
API CALL
kekxv May 9, 2026
7aff4f2
API CALL
kekxv May 9, 2026
b71bb79
publish_to_bcr.yml
kekxv May 9, 2026
fbe2289
Merge branch 'main' into develop
kekxv May 9, 2026
7a1bd41
fix: ubuntu ci
kekxv May 9, 2026
6509c37
Merge branch 'ClangTools:main' into main
kekxv May 9, 2026
44baa70
update: version
kekxv Jun 24, 2026
d178396
Merge remote-tracking branch 'origin/main'
kekxv Jun 24, 2026
eb13e03
fix: 隐藏的问题修复
kekxv Jun 25, 2026
f84f896
fix: 隐藏的问题修复
kekxv Jun 25, 2026
722f788
fix: 隐藏的问题修复
kekxv Jun 25, 2026
49add75
fix: 隐藏的问题修复 - 1
kekxv Jun 25, 2026
d3a4b43
fix: 隐藏的问题修复 - 2
kekxv Jun 25, 2026
b97503f
fix: 修改日志为spdlog
kekxv Jun 25, 2026
96e8386
fix: windows ci/cd
kekxv Jun 25, 2026
a654fb8
fix: windows ci/cd
kekxv Jun 25, 2026
e1c9676
fix: windows ci/cd
kekxv Jun 25, 2026
a38e6c5
fix: windows ci/cd
kekxv Jun 25, 2026
23ff4b9
fix: Linux ci/cd
kekxv Jun 25, 2026
0d3e5b4
fix: Linux ci/cd
kekxv Jun 25, 2026
08cf472
fix: Linux ci/cd
kekxv Jun 25, 2026
a451d10
fix: Linux ci/cd
kekxv Jun 25, 2026
e4b9144
update: version
kekxv Jun 25, 2026
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
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#build --@boost.mysql//:ssl=boringssl
build --@boost.mysql//:ssl=boringssl
build --@boost.asio//:ssl=boringssl
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9.1.1
2 changes: 1 addition & 1 deletion .github/workflows/bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:

- name: Bazel Test
run: |
bazel test framework/...
bazel test framework/... --test_output=errors --test_verbose_timeout_warnings --verbose_failures
example:
needs: build
strategy:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ node_modules
/.clwb/targets/
/.clwb/aspects/
.clwb
web_root
web_root
MODULE.bazel.lock
46 changes: 19 additions & 27 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
module(
name = "khttpd",
version = "0.1.0",
version = "0.2.0",
)

bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_cc", version = "0.2.13")
bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "rules_perl", version = "0.4.3")
bazel_dep(name = "rules_foreign_cc", version = "0.14.0")
single_version_override(
module_name = "rules_foreign_cc",
patches = [
"//patches:rules_foreign_cc/foreign_cc.built_tools.pkgconfig_build.bzl.patch",
],
version = "0.14.0",
)

bazel_dep(name = "fmt", version = "12.0.0")
bazel_dep(name = "platforms", version = "1.1.0")
bazel_dep(name = "bazel_skylib", version = "1.9.0")
bazel_dep(name = "rules_cc", version = "0.2.20")
bazel_dep(name = "rules_shell", version = "0.8.0")
bazel_dep(name = "rules_perl", version = "1.1.1")
bazel_dep(name = "fmt", version = "12.1.0")
bazel_dep(name = "googletest", version = "1.17.0.bcr.2")
bazel_dep(name = "sqlite3", version = "3.50.4")
bazel_dep(name = "openssl", version = "3.3.1.bcr.9")
bazel_dep(name = "boringssl", version = "0.20251110.0")
bazel_dep(name = "boost", version = "1.89.0.bcr.2")
bazel_dep(name = "boost.asio", version = "1.89.0.bcr.2")
bazel_dep(name = "boost.json", version = "1.89.0.bcr.2")
bazel_dep(name = "boost.mysql", version = "1.89.0.bcr.2")
bazel_dep(name = "boost.beast", version = "1.89.0.bcr.2")
bazel_dep(name = "boost.filesystem", version = "1.89.0.bcr.2")
bazel_dep(name = "boost.url", version = "1.89.0.bcr.2")
bazel_dep(name = "boost.uuid", version = "1.89.0.bcr.2")
bazel_dep(name = "sqlite3", version = "3.53.2")
bazel_dep(name = "openssl", version = "3.5.5.bcr.4")
bazel_dep(name = "boringssl", version = "0.20260616.0")
bazel_dep(name = "boost", version = "1.90.0.bcr.1")
bazel_dep(name = "boost.asio", version = "1.90.0.bcr.1")
bazel_dep(name = "boost.json", version = "1.90.0.bcr.1")
bazel_dep(name = "boost.mysql", version = "1.90.0.bcr.1")
bazel_dep(name = "boost.beast", version = "1.90.0.bcr.1")
bazel_dep(name = "boost.filesystem", version = "1.90.0.bcr.1")
bazel_dep(name = "boost.url", version = "1.90.0.bcr.1")
bazel_dep(name = "boost.uuid", version = "1.90.0.bcr.1")
bazel_dep(name = "spdlog", version = "1.17.0")

cc_configure = use_extension("@rules_cc//cc:extensions.bzl", "cc_configure_extension")
use_repo(cc_configure, "local_config_cc")
984 changes: 0 additions & 984 deletions MODULE.bazel.lock

This file was deleted.

1 change: 1 addition & 0 deletions example/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ cc_binary(
],
deps = [
"@khttpd",
"@spdlog//:spdlog",
],
)
9 changes: 5 additions & 4 deletions example/HelloWsController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define HELLOWSCONTROLLER_HPP

#include "controller/http_controller.hpp"
#include <spdlog/spdlog.h>

class HelloWsController : public khttpd::framework::BaseController<HelloWsController>
{
Expand Down Expand Up @@ -41,23 +42,23 @@ class HelloWsController : public khttpd::framework::BaseController<HelloWsContro

void onopen(khttpd::framework::WebsocketContext& ctx)
{
fmt::print("[WS: {}] Connection opened.\n", ctx.path);
spdlog::info("[WS: {}] Connection opened.", ctx.path);
ctx.send("Welcome to the echo service!");
}

void onclose(khttpd::framework::WebsocketContext& ctx)
{
fmt::print("[WS: {}] Connection closed.\n", ctx.path);
spdlog::info("[WS: {}] Connection closed.", ctx.path);
}

void onerror(khttpd::framework::WebsocketContext& ctx)
{
fmt::print(stderr, "[WS: {}] Error: {}\n", ctx.path, ctx.error_code.message());
spdlog::error("[WS: {}] Error: {}", ctx.path, ctx.error_code.message());
}

void onmessage(khttpd::framework::WebsocketContext& ctx)
{
fmt::print("[WS: {}] Received: {}\n", ctx.path, ctx.message);
spdlog::info("[WS: {}] Received: {}", ctx.path, ctx.message);
ctx.send("Echo: " + ctx.message, ctx.is_text);
}
};
Expand Down
3 changes: 2 additions & 1 deletion example/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ bazel_dep(name = "rules_cc", version = "0.2.13")
bazel_dep(name = "boost", version = "1.89.0.bcr.2")
bazel_dep(name = "boost.asio", version = "1.89.0.bcr.2")
bazel_dep(name = "boost.mysql", version = "1.89.0.bcr.2")
bazel_dep(name = "khttpd", version = "0.1.0")
bazel_dep(name = "spdlog", version = "1.17.0")
bazel_dep(name = "khttpd", version = "0.2.0")
local_path_override(
module_name = "khttpd",
path = "..",
Expand Down
24 changes: 12 additions & 12 deletions example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <boost/asio/ip/tcp.hpp>
#include <thread>
#include <memory>
#include <fmt/base.h>
#include <fmt/format.h>
#include <spdlog/spdlog.h>

#include "HelloController.hpp"
#include "HelloStreamController.hpp"
Expand All @@ -24,7 +24,7 @@ int main(int argc, char* argv[])
auto const port = static_cast<unsigned short>(8080);
auto const num_threads = std::max<int>(1, static_cast<int>(std::thread::hardware_concurrency()));

fmt::print("Starting khttpd server with {} worker threads...\n", num_threads);
spdlog::info("Starting khttpd server with {} worker threads...", num_threads);

// 定义 Web 根目录
std::string web_root_path = "web_root";
Expand Down Expand Up @@ -145,7 +145,7 @@ int main(int argc, char* argv[])
{
response_msg += fmt::format("Uploaded File: {} ({} bytes, type: {})\n", file.filename, file.data.length(),
file.content_type);
// fmt::print("File '{}' content: \n{}\n", file.filename, file.data);
// spdlog::debug("File '{}' content: \n{}", file.filename, file.data);
}
}
else
Expand Down Expand Up @@ -225,24 +225,24 @@ int main(int argc, char* argv[])
// onopen
[]([[maybe_unused]] khttpd::framework::WebsocketContext& ctx)
{
fmt::print("[WS: {}] Connection opened.\n", ctx.path);
spdlog::info("[WS: {}] Connection opened.", ctx.path);
ctx.send("Welcome to the echo service!");
},
// onmessage
[](khttpd::framework::WebsocketContext& ctx)
{
fmt::print("[WS: {}] Received: {}\n", ctx.path, ctx.message);
spdlog::info("[WS: {}] Received: {}", ctx.path, ctx.message);
ctx.send("Echo: " + ctx.message, ctx.is_text);
},
// onclose
[]([[maybe_unused]] khttpd::framework::WebsocketContext& ctx)
{
fmt::print("[WS: {}] Connection closed.\n", ctx.path);
spdlog::info("[WS: {}] Connection closed.", ctx.path);
},
// onerror
[](khttpd::framework::WebsocketContext& ctx)
{
fmt::print(stderr, "[WS: {}] Error: {}\n", ctx.path, ctx.error_code.message());
spdlog::error("[WS: {}] Error: {}", ctx.path, ctx.error_code.message());
}
);

Expand All @@ -251,30 +251,30 @@ int main(int argc, char* argv[])
// onopen
[]([[maybe_unused]] khttpd::framework::WebsocketContext& ctx)
{
fmt::print("[WS: {}] Chat connection opened. Say hello!\n", ctx.path);
spdlog::info("[WS: {}] Chat connection opened. Say hello!", ctx.path);
ctx.send("Welcome to the chat!");
},
// onmessage
[](khttpd::framework::WebsocketContext& ctx)
{
fmt::print("[WS: {}] Chat message: {}\n", ctx.path, ctx.message);
spdlog::info("[WS: {}] Chat message: {}", ctx.path, ctx.message);
ctx.send("You said: " + ctx.message, ctx.is_text);
},
// onclose
[]([[maybe_unused]] khttpd::framework::WebsocketContext& ctx)
{
fmt::print("[WS: {}] Chat connection closed.\n", ctx.path);
spdlog::info("[WS: {}] Chat connection closed.", ctx.path);
},
// onerror
[](khttpd::framework::WebsocketContext& ctx)
{
fmt::print(stderr, "[WS: {}] Chat error: {}\n", ctx.path, ctx.error_code.message());
spdlog::error("[WS: {}] Chat error: {}", ctx.path, ctx.error_code.message());
}
);

server->run();

fmt::print("Application exited.\n");
spdlog::info("Application exited.");

return 0;
}
1 change: 1 addition & 0 deletions framework/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ cc_library(
"@boost.url",
"@boost.uuid",
"@fmt", # 用于日志输出
"@spdlog//:spdlog",
],
)
1 change: 1 addition & 0 deletions framework/client/host_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace khttpd::framework::client
}

std::uniform_int_distribution<int> dist(1, total_weight_);
std::lock_guard<std::mutex> lock{rng_mutex_};
int r = dist(rng_);

auto it = std::lower_bound(cumulative_weights_.begin(), cumulative_weights_.end(), r);
Expand Down
2 changes: 2 additions & 0 deletions framework/client/host_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>
#include <vector>
#include <random>
#include <mutex>

namespace khttpd::framework::client
{
Expand Down Expand Up @@ -34,6 +35,7 @@ namespace khttpd::framework::client
std::vector<int> cumulative_weights_;
int total_weight_;
std::mt19937 rng_;
std::mutex rng_mutex_;
};
}

Expand Down
Loading
Loading