Files

40 lines
1.3 KiB
C++

#pragma once
#include "Global.h"
#include "Export.h"
#include "IPTable.h"
#include "HTTPObjects.h"
class UNSWSC_DLL_EXPORT ServerProcessor
{
protected:
class Impl;
std::unique_ptr<Impl> pimpl;
public:
ServerProcessor();
virtual ~ServerProcessor();
public:
void EnableIPCheck();
void DisableIPCheck();
void UpdateBlockedIPList(IPTablePtr ips);
void AppenedBlockedIP(DateTime::Span block_time, std::string ip);
uns::HTTPMethod GetMethod(uns::RequestPtr request);
void AddStreamSettings(std::string method, bool stream);
public:
// 主接口,重载以实现对请求的处理
virtual uns::ResponsePtr Processor(uns::RequestPtr request) = 0;
// 路径穿越配置,重载以配置允许的路径穿越类型
virtual uns::PathTraversalDefenceLevel PTDefence();
// 路径穿越防护,重载以实现路径穿越检查,配置为AutoNormalize或AllowNormal时必须,否则自动退化为DenyAll
virtual bool IsPathSafe(const std::string& raw_path);
// 请求头预检,重载以实现在接收请求体之前检查请求头,返回false则服务器将强制关闭连接
virtual bool IsHeaderValid(uns::RequestPtr request);
public:
uns::ResponsePtr Handle(uns::RequestPtr request);
bool Stream(const std::string& method);
};
using ServerProcessorPtr = std::shared_ptr<ServerProcessor>;