flatten 20260225
This commit is contained in:
96
tjp/core/http/Server.hpp
Executable file
96
tjp/core/http/Server.hpp
Executable file
@@ -0,0 +1,96 @@
|
||||
// TJP COPYRIGHT HEADER
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Server.h"
|
||||
#include "Component.h"
|
||||
#include "Types.hpp"
|
||||
#include <tjp/core/header_only/compile.h>
|
||||
|
||||
#include <tjp/core/ptr/Ptr.h>
|
||||
#include <tjp/core/string/String.h>
|
||||
#include <tjp/core/string/StringView.h>
|
||||
#include <tjp/core/containers/Function.h>
|
||||
|
||||
#include "as_future.hpp"
|
||||
|
||||
namespace tjp::core::http {
|
||||
|
||||
struct Server
|
||||
{
|
||||
virtual ~Server() {}
|
||||
|
||||
virtual void add(
|
||||
const StrongPtr<Component> &component,
|
||||
const String &urlPrefix = {}
|
||||
) = 0;
|
||||
|
||||
template<typename ... Args>
|
||||
void addAll(Args && ...args)
|
||||
{
|
||||
(add(std::forward<Args>(args)), ...);
|
||||
}
|
||||
|
||||
virtual void setNumThreads(size_t) = 0;
|
||||
virtual void start(const String &bindTo, int port) = 0;
|
||||
virtual void run(const String &bindTo, int port) = 0;
|
||||
virtual void stop() = 0;
|
||||
|
||||
virtual bool isRunning() = 0;
|
||||
|
||||
virtual void bind(
|
||||
const Method &method,
|
||||
Matcher &&matcher,
|
||||
FutureHandler &&
|
||||
) = 0;
|
||||
|
||||
void bind(
|
||||
const Method &method,
|
||||
const Pattern &pattern,
|
||||
FutureHandler &&handler
|
||||
)
|
||||
{
|
||||
bind(
|
||||
method,
|
||||
match_regex(String(pattern)),
|
||||
std::move(handler)
|
||||
);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
void bind_with(
|
||||
const Method &method,
|
||||
Matcher matcher,
|
||||
F &&f
|
||||
)
|
||||
{
|
||||
bind(
|
||||
method,
|
||||
std::move(matcher),
|
||||
as_future(
|
||||
std::forward<F>(f)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
void bind_with(
|
||||
const Method &method,
|
||||
const Pattern &pattern,
|
||||
F &&f
|
||||
)
|
||||
{
|
||||
bind_with(
|
||||
method,
|
||||
match_regex(String(pattern)),
|
||||
std::forward<F>(f)
|
||||
);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#ifdef TJP_CORE_HEADER_ONLY
|
||||
#include "Server.cpp"
|
||||
#endif
|
||||
Reference in New Issue
Block a user