mirror of
https://gitee.com/xia-chu/ZLMediaKit.git
synced 2026-05-06 10:57:50 +08:00
修复http代理的两个问题,原http代理功能提交(#2988):d593267 (#4219)
Some checks failed
Android / build (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docker / build (push) Has been cancelled
Linux / build (push) Has been cancelled
macOS / build (push) Has been cancelled
Windows / build (push) Has been cancelled
Some checks failed
Android / build (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docker / build (push) Has been cancelled
Linux / build (push) Has been cancelled
macOS / build (push) Has been cancelled
Windows / build (push) Has been cancelled
1. CONNECT请求添加Host字段, 解决400 bad request问题;
2. HLS拉取第2个ts分片时,重新设置http代理,解决第2个分片及后续分片未走代理的问题。
This commit is contained in:
parent
8ff1459789
commit
dfca520857
@ -133,6 +133,10 @@ void HlsPlayer::fetchSegment() {
|
||||
if (!(*this)[Client::kNetAdapter].empty()) {
|
||||
_http_ts_player->setNetAdapter((*this)[Client::kNetAdapter]);
|
||||
}
|
||||
} else {
|
||||
// 每次请求新的ts片段时重置HttpTSPlayer状态
|
||||
_http_ts_player->clear();
|
||||
_http_ts_player->setProxyUrl((*this)[Client::kProxyUrl]);
|
||||
}
|
||||
|
||||
Ticker ticker;
|
||||
|
||||
@ -103,6 +103,8 @@ void HttpClient::clear() {
|
||||
_user_set_header.clear();
|
||||
_body.reset();
|
||||
_method.clear();
|
||||
// 重置代理连接状态
|
||||
_proxy_connected = false;
|
||||
clearResponse();
|
||||
}
|
||||
|
||||
@ -182,6 +184,8 @@ void HttpClient::onConnect_l(const SockException &ex) {
|
||||
_path.clear();
|
||||
} else {
|
||||
printer << "CONNECT " << _last_host << " HTTP/1.1\r\n";
|
||||
printer << "Host: " << _last_host << "\r\n";
|
||||
printer << "User-Agent: " << kServerName << "\r\n";
|
||||
printer << "Proxy-Connection: keep-alive\r\n";
|
||||
if (!_proxy_auth.empty()) {
|
||||
printer << "Proxy-Authorization: Basic " << _proxy_auth << "\r\n";
|
||||
@ -482,9 +486,14 @@ void HttpClient::setProxyUrl(string proxy_url) {
|
||||
}
|
||||
|
||||
bool HttpClient::checkProxyConnected(const char *data, size_t len) {
|
||||
auto ret = strstr(data, "HTTP/1.1 200 Connection established");
|
||||
_proxy_connected = ret != nullptr;
|
||||
return _proxy_connected;
|
||||
string response(data, len);
|
||||
if (response.find("HTTP/1.1 200") != string::npos || response.find("HTTP/1.0 200") != string::npos) {
|
||||
_proxy_connected = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
_proxy_connected = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void HttpClient::setAllowResendRequest(bool allow) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user