增加websocket支持
This commit is contained in:
@@ -34,12 +34,64 @@
|
||||
#define HTTP_INTERCEPTOR_PRINT 0
|
||||
// http lua 引擎
|
||||
//#define HTTP_LUA_ENGINE 0
|
||||
|
||||
|
||||
|
||||
|
||||
namespace ylib
|
||||
{
|
||||
namespace network
|
||||
{
|
||||
namespace http
|
||||
{
|
||||
/// <summary>
|
||||
/// 消息类型
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
||||
enum message_type {
|
||||
// 普通
|
||||
HTTP_SERVER_MESSAGE_TYPE_NORMAL = 0,
|
||||
// WebSocket
|
||||
HTTP_SERVER_MESSAGE_TYPE_WEBSOCKET = 1,
|
||||
};
|
||||
enum ws_type {
|
||||
// 升级
|
||||
HTTP_SERVER_WEBSOCKET_TYPE_UPGRADE = 0,
|
||||
// 消息头
|
||||
HTTP_SERVER_WEBSOCKET_TYPE_MESSAGE_HEADER = 1,
|
||||
// 消息包
|
||||
HTTP_SERVER_WEBSOCKET_TYPE_MESSAGE_BODY = 2,
|
||||
// 关闭
|
||||
HTTP_SERVER_WEBSOCKET_TYPE_CLOSE = 3,
|
||||
};
|
||||
struct websocket_message {
|
||||
struct ws_header {
|
||||
// 是否结束帧
|
||||
bool _final = false;
|
||||
// 帧操作码
|
||||
// 0x0 连续帧
|
||||
// 0x1 文本帧
|
||||
// 0x2 二进制帧
|
||||
// 0x3-7 为非控制帧保留
|
||||
// 0x8 连接关闭
|
||||
// 0x9 ping
|
||||
// 0xA pong
|
||||
// 0xB-F 为控制帧保留
|
||||
int opcode = 0x00;
|
||||
// 是否使用掩码
|
||||
uchar mask[4] = {0};
|
||||
// 长度
|
||||
uint64 length = 0;
|
||||
};
|
||||
|
||||
ws_type type;
|
||||
ws_header header;
|
||||
|
||||
std::string sec_websocket_key;
|
||||
std::string filepath;
|
||||
uint64 connid = 0;
|
||||
};
|
||||
/// <summary>
|
||||
/// 服务端缓存
|
||||
/// </summary>
|
||||
@@ -187,6 +239,8 @@ namespace ylib
|
||||
std::map<std::string, ssl_config> cert;
|
||||
// 最大上传大小限制
|
||||
uint64 max_upload_size = 0;
|
||||
// 支持WebSocket
|
||||
bool websocket_enable = false;
|
||||
};
|
||||
|
||||
class agent;
|
||||
@@ -221,6 +275,12 @@ namespace ylib
|
||||
std::string host;
|
||||
// 缓存路径
|
||||
ylib::file_io cache_file;
|
||||
// WS自定义数据
|
||||
std::string ws_filepath;
|
||||
// 是WS
|
||||
bool is_ws = false;
|
||||
// WS消息
|
||||
websocket_message ws_msg;
|
||||
};
|
||||
// 代理
|
||||
struct proxy
|
||||
@@ -270,6 +330,9 @@ namespace ylib
|
||||
size_t offset = 0;
|
||||
size_t length = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user