48 lines
1 KiB
C
48 lines
1 KiB
C
|
#pragma once
|
||
|
|
||
|
#include "MiddleWare.h"
|
||
|
|
||
|
#include <functional>
|
||
|
#include <thread>
|
||
|
|
||
|
|
||
|
namespace VWeb {
|
||
|
typedef std::function<PreMiddleWareReturn(Request &req)> AuthFunction;
|
||
|
class AuthWare : public MiddleWare {
|
||
|
public:
|
||
|
AuthWare() = default;
|
||
|
~AuthWare() = default;
|
||
|
PreMiddleWareReturn PreHandle(Request &request) override;
|
||
|
void SetAuthMethod(AuthFunction function) {
|
||
|
m_AuthFunction = std::move(function);
|
||
|
}
|
||
|
|
||
|
protected:
|
||
|
AuthFunction m_AuthFunction{nullptr};
|
||
|
};
|
||
|
|
||
|
class SessionManager : public MiddleWare {
|
||
|
public:
|
||
|
SessionManager();
|
||
|
~SessionManager();
|
||
|
PreMiddleWareReturn PreHandle(Request &request) override;
|
||
|
bool PostHandle(Request &request, Response &response) override;
|
||
|
|
||
|
protected:
|
||
|
void GC();
|
||
|
|
||
|
protected:
|
||
|
Ref<std::thread> m_GCThread;
|
||
|
std::mutex m_Mutex;
|
||
|
std::unordered_map<std::string, Ref<Session>> m_Sessions;
|
||
|
int m_Counter{-1};
|
||
|
bool m_IsRunning{true};
|
||
|
};
|
||
|
|
||
|
class CookieManager : public MiddleWare {
|
||
|
public:
|
||
|
CookieManager() = default;
|
||
|
~CookieManager() = default;
|
||
|
PreMiddleWareReturn PreHandle(Request &) override;
|
||
|
};
|
||
|
} // namespace VWeb
|