修复http客户端复用header无法更新的bug: #1349

This commit is contained in:
ziyue 2022-01-11 10:44:49 +08:00
parent 60f11df1ea
commit fdcc29e0ed
2 changed files with 7 additions and 3 deletions

View File

@ -41,6 +41,8 @@ void HttpClient::sendRequest(const string &url, float timeout_sec, float recv_ti
if (_path.empty()) {
_path = "/";
}
//重新设置header防止上次请求的header干扰
_header = _user_set_header;
auto pos = host.find('@');
if (pos != string::npos) {
//去除?后面的字符串
@ -94,6 +96,7 @@ void HttpClient::sendRequest(const string &url, float timeout_sec, float recv_ti
void HttpClient::clear() {
_url.clear();
_header.clear();
_user_set_header.clear();
_body.reset();
_method.clear();
_path.clear();
@ -116,14 +119,14 @@ void HttpClient::setMethod(string method) {
}
void HttpClient::setHeader(HttpHeader header) {
_header = std::move(header);
_user_set_header = std::move(header);
}
HttpClient &HttpClient::addHeader(string key, string val, bool force) {
if (!force) {
_header.emplace(std::move(key), std::move(val));
_user_set_header.emplace(std::move(key), std::move(val));
} else {
_header[std::move(key)] = std::move(val);
_user_set_header[std::move(key)] = std::move(val);
}
return *this;
}

View File

@ -181,6 +181,7 @@ private:
bool _complete = false;
string _url;
HttpHeader _header;
HttpHeader _user_set_header;
HttpBody::Ptr _body;
string _method;
string _path;