feat(net): implement VL-004 HttpServer and VL-005 streaming HttpClient with secure TLS
This commit is contained in:
1 parent
22c8538754
commit
66baae74a0
12 files changed
+3984
-119
No files matched your search
@@ -260,6 +260,21 @@ namespace Void::Net
|
||||
return find_header(headers, name);
|
||||
}
|
||||
|
||||
ServerResponse ServerResponse::from_file(std::filesystem::path path,
|
||||
std::string content_type,
|
||||
std::uint16_t status)
|
||||
{
|
||||
if (content_type.empty()) {
|
||||
content_type = std::string{content_type_for(path)};
|
||||
}
|
||||
return ServerResponse{
|
||||
.status = status,
|
||||
.headers = {Header{"Content-Type", std::move(content_type)}},
|
||||
.body = {},
|
||||
.file_body = std::move(path),
|
||||
};
|
||||
}
|
||||
|
||||
std::optional<std::string_view>
|
||||
ServerResponse::header(std::string_view name) const noexcept
|
||||
{
|
||||
@@ -334,6 +349,25 @@ namespace Void::Net
|
||||
return std::optional<ServerResponse>{std::move(*response)};
|
||||
}
|
||||
|
||||
std::vector<Method> Router::allowed_methods(std::string_view path) const
|
||||
{
|
||||
if (path.empty() || !path.starts_with('/')) {
|
||||
return {};
|
||||
}
|
||||
const auto segments = split_path(path_only(path));
|
||||
std::vector<Method> methods;
|
||||
{
|
||||
std::shared_lock lock{mutex_};
|
||||
for (const auto& route : routes_) {
|
||||
if (match_route(route.segments, segments).has_value() &&
|
||||
std::ranges::find(methods, route.method) == methods.end()) {
|
||||
methods.push_back(route.method);
|
||||
}
|
||||
}
|
||||
}
|
||||
return methods;
|
||||
}
|
||||
|
||||
std::size_t Router::size() const
|
||||
{
|
||||
std::shared_lock lock{mutex_};
|
||||
|
||||
Reference in new issue
Block a user