mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
修复http客户端复用header无法更新的bug: #1349
This commit is contained in:
parent
60f11df1ea
commit
fdcc29e0ed
@ -41,6 +41,8 @@ void HttpClient::sendRequest(const string &url, float timeout_sec, float recv_ti
|
|||||||
if (_path.empty()) {
|
if (_path.empty()) {
|
||||||
_path = "/";
|
_path = "/";
|
||||||
}
|
}
|
||||||
|
//重新设置header,防止上次请求的header干扰
|
||||||
|
_header = _user_set_header;
|
||||||
auto pos = host.find('@');
|
auto pos = host.find('@');
|
||||||
if (pos != string::npos) {
|
if (pos != string::npos) {
|
||||||
//去除?后面的字符串
|
//去除?后面的字符串
|
||||||
@ -94,6 +96,7 @@ void HttpClient::sendRequest(const string &url, float timeout_sec, float recv_ti
|
|||||||
void HttpClient::clear() {
|
void HttpClient::clear() {
|
||||||
_url.clear();
|
_url.clear();
|
||||||
_header.clear();
|
_header.clear();
|
||||||
|
_user_set_header.clear();
|
||||||
_body.reset();
|
_body.reset();
|
||||||
_method.clear();
|
_method.clear();
|
||||||
_path.clear();
|
_path.clear();
|
||||||
@ -116,14 +119,14 @@ void HttpClient::setMethod(string method) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HttpClient::setHeader(HttpHeader header) {
|
void HttpClient::setHeader(HttpHeader header) {
|
||||||
_header = std::move(header);
|
_user_set_header = std::move(header);
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpClient &HttpClient::addHeader(string key, string val, bool force) {
|
HttpClient &HttpClient::addHeader(string key, string val, bool force) {
|
||||||
if (!force) {
|
if (!force) {
|
||||||
_header.emplace(std::move(key), std::move(val));
|
_user_set_header.emplace(std::move(key), std::move(val));
|
||||||
} else {
|
} else {
|
||||||
_header[std::move(key)] = std::move(val);
|
_user_set_header[std::move(key)] = std::move(val);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -181,6 +181,7 @@ private:
|
|||||||
bool _complete = false;
|
bool _complete = false;
|
||||||
string _url;
|
string _url;
|
||||||
HttpHeader _header;
|
HttpHeader _header;
|
||||||
|
HttpHeader _user_set_header;
|
||||||
HttpBody::Ptr _body;
|
HttpBody::Ptr _body;
|
||||||
string _method;
|
string _method;
|
||||||
string _path;
|
string _path;
|
||||||
|
Loading…
Reference in New Issue
Block a user