Initial dstalk project: core DLL + CLI + BearSSL TLS
- Core DLL: AI API client (DeepSeek/OpenAI compatible), HTTP(S) via Boost.Beast - BearSSL vendored as TLS backend (MIT license, replacing OpenSSL) - CLI frontend with ANSI colors, /help /model /file /save /load commands - WinHTTP alternative HTTP client for Windows - GPLv3 license with linking exception - Build: CMake + Ninja + Clang, dependencies via Conan2 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
54
dstalk-core/src/net/http_client.hpp
Normal file
54
dstalk-core/src/net/http_client.hpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace dstalk {
|
||||
namespace net {
|
||||
|
||||
struct HttpResponse {
|
||||
int status_code = 0;
|
||||
std::string body;
|
||||
std::unordered_map<std::string, std::string> headers;
|
||||
};
|
||||
|
||||
/*
|
||||
* HTTPS 客户端统一接口
|
||||
* Windows: WinHTTP 实现 (零依赖)
|
||||
* 其他平台: Boost.Beast + OpenSSL 实现
|
||||
*/
|
||||
class HttpClient {
|
||||
public:
|
||||
HttpClient();
|
||||
~HttpClient();
|
||||
|
||||
void set_timeout(int connect_sec, int request_sec);
|
||||
|
||||
// 同步 POST JSON, 返回完整响应
|
||||
HttpResponse post_json(
|
||||
const std::string& host,
|
||||
const std::string& port,
|
||||
const std::string& target,
|
||||
const std::string& json_body,
|
||||
const std::unordered_map<std::string, std::string>& extra_headers
|
||||
);
|
||||
|
||||
// 流式 POST (SSE 逐行回调), on_line 返回 false 提前终止
|
||||
using StreamCallback = std::function<bool(const std::string& line)>;
|
||||
HttpResponse post_stream(
|
||||
const std::string& host,
|
||||
const std::string& port,
|
||||
const std::string& target,
|
||||
const std::string& json_body,
|
||||
const std::unordered_map<std::string, std::string>& extra_headers,
|
||||
StreamCallback on_line
|
||||
);
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
Impl* impl_;
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
} // namespace dstalk
|
||||
Reference in New Issue
Block a user