Simplifies the active Windows build path around Boost.Beast/OpenSSL, fixes VS2017/clang-cl compatibility, and removes unused BearSSL/WinHTTP remnants so the project builds and tests cleanly. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
54 lines
1.2 KiB
C++
54 lines
1.2 KiB
C++
#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 客户端统一接口
|
|
* 所有平台统一使用 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
|