From fdcc29e0eddd40adc53df4bec63ab0d92e756ba9 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Tue, 11 Jan 2022 10:44:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dhttp=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E5=A4=8D=E7=94=A8header=E6=97=A0=E6=B3=95=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=9A=84bug:=20#1349?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/HttpClient.cpp | 9 ++++++--- src/Http/HttpClient.h | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Http/HttpClient.cpp b/src/Http/HttpClient.cpp index d0cc9dc9..45ef2790 100644 --- a/src/Http/HttpClient.cpp +++ b/src/Http/HttpClient.cpp @@ -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; } diff --git a/src/Http/HttpClient.h b/src/Http/HttpClient.h index 01ac795a..1f0b35ee 100644 --- a/src/Http/HttpClient.h +++ b/src/Http/HttpClient.h @@ -181,6 +181,7 @@ private: bool _complete = false; string _url; HttpHeader _header; + HttpHeader _user_set_header; HttpBody::Ptr _body; string _method; string _path;