增加http代理功能 (#2988)

支持通过http代理拉流, 避免内外网复杂网络环境时需要专门配置防火墙,现在只需要配置一台代理内网的服务器.

---------

Co-authored-by: xia-chu <771730766@qq.com>
This commit is contained in:
alexliyu7352
2023-11-23 11:09:01 +08:00
committed by GitHub
parent a13b8417e5
commit d593267f61
11 changed files with 115 additions and 17 deletions

View File

@@ -11,7 +11,7 @@
#include <cinttypes>
#include "Parser.h"
#include "strCoding.h"
#include "macros.h"
#include "Util/base64.h"
#include "Network/sockutil.h"
#include "Common/macros.h"
@@ -325,6 +325,25 @@ void splitUrl(const std::string &url, std::string &host, uint16_t &port) {
host = url.substr(0, pos);
checkHost(host);
}
void parseProxyUrl(const std::string &proxy_url, std::string &proxy_host, uint16_t &proxy_port, std::string &proxy_auth) {
// 判断是否包含http://, 如果是则去掉
std::string host;
auto pos = proxy_url.find("://");
if (pos != string::npos) {
host = proxy_url.substr(pos + 3);
} else {
host = proxy_url;
}
// 判断是否包含用户名和密码
pos = host.rfind('@');
if (pos != string::npos) {
proxy_auth = encodeBase64(host.substr(0, pos));
host = host.substr(pos + 1, host.size());
}
splitUrl(host, proxy_host, proxy_port);
}
#if 0
//测试代码
static onceToken token([](){

View File

@@ -21,6 +21,8 @@ namespace mediakit {
std::string findSubString(const char *buf, const char *start, const char *end, size_t buf_size = 0);
// 把url解析为主机地址和端口号,兼容ipv4/ipv6/dns
void splitUrl(const std::string &url, std::string &host, uint16_t &port);
// 解析proxy url,仅支持http
void parseProxyUrl(const std::string &proxy_url, std::string &proxy_host, uint16_t &proxy_port, std::string &proxy_auth);
struct StrCaseCompare {
bool operator()(const std::string &__x, const std::string &__y) const { return strcasecmp(__x.data(), __y.data()) < 0; }

View File

@@ -353,6 +353,7 @@ const string kBeatIntervalMS = "beat_interval_ms";
const string kBenchmarkMode = "benchmark_mode";
const string kWaitTrackReady = "wait_track_ready";
const string kPlayTrack = "play_track";
const string kProxyUrl = "proxy_url";
} // namespace Client
} // namespace mediakit

View File

@@ -403,6 +403,8 @@ extern const std::string kWaitTrackReady;
// rtsp播放指定track可选项有0(不指定,默认)、1(视频)、2(音频)
// 设置方法:player[Client::kPlayTrack] = 0/1/2;
extern const std::string kPlayTrack;
//设置代理url目前只支持http协议
extern const std::string kProxyUrl;
} // namespace Client
} // namespace mediakit