diff --git a/server/WebHook.cpp b/server/WebHook.cpp index 60af4d02..f160ab16 100644 --- a/server/WebHook.cpp +++ b/server/WebHook.cpp @@ -492,4 +492,4 @@ void installWebHook(){ void unInstallWebHook(){ -} \ No newline at end of file +} diff --git a/src/Http/HttpClient.cpp b/src/Http/HttpClient.cpp index 8a23a8b2..9d85f5b1 100644 --- a/src/Http/HttpClient.cpp +++ b/src/Http/HttpClient.cpp @@ -69,17 +69,16 @@ void HttpClient::sendRequest(const string &strUrl, float fTimeOutSec) { //服务器域名 host = FindField(host.data(), NULL, ":"); } - _header.emplace(string("Host"), host); - _header.emplace(string("Tools"), "ZLMediaKit"); - _header.emplace(string("Connection"), "keep-alive"); - _header.emplace(string("Accept"), "*/*"); - _header.emplace(string("Accept-Language"), "zh-CN,zh;q=0.8"); - _header.emplace(string("User-Agent"), - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36"); + _header.emplace("Host", host); + _header.emplace("Tools", "ZLMediaKit"); + _header.emplace("Connection", "keep-alive"); + _header.emplace("Accept", "*/*"); + _header.emplace("Accept-Language", "zh-CN,zh;q=0.8"); + _header.emplace("User-Agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36"); if (_body && _body->remainSize()) { - _header.emplace(string("Content-Length"), to_string(_body->remainSize())); - _header.emplace(string("Content-Type"), "application/x-www-form-urlencoded; charset=UTF-8"); + _header.emplace("Content-Length", to_string(_body->remainSize())); + _header.emplace("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); } bool bChanged = (_lastHost != host + ":" + to_string(port)) || (_isHttps != isHttps); @@ -94,7 +93,7 @@ void HttpClient::sendRequest(const string &strUrl, float fTimeOutSec) { } if(!printer.empty()){ printer.pop_back(); - _header.emplace(string("Cookie"), printer); + _header.emplace("Cookie", printer); } diff --git a/src/Rtsp/Rtsp.h b/src/Rtsp/Rtsp.h index 8da208be..60f03a0e 100644 --- a/src/Rtsp/Rtsp.h +++ b/src/Rtsp/Rtsp.h @@ -125,15 +125,30 @@ struct StrCaseCompare { class StrCaseMap : public multimap{ public: + typedef multimap Super ; StrCaseMap() = default; ~StrCaseMap() = default; string &operator[](const string &key){ auto it = find(key); if(it == end()){ - it = emplace(key,""); + it = Super::emplace(key,""); } return it->second; } + + template + void emplace(K &&k , V &&v) { + auto it = find(k); + if(it != end()){ + return; + } + Super::emplace(std::forward(k),std::forward(v)); + } + + template + void emplace_force(K &&k , V &&v) { + Super::emplace(std::forward(k),std::forward(v)); + } }; class Parser { @@ -167,7 +182,7 @@ public: auto field = FindField(line.data(), NULL, ": "); auto value = FindField(line.data(), ": ", NULL); if (field.size() != 0) { - _mapHeaders.emplace(field,value); + _mapHeaders.emplace_force(field,value); } } start = start + line.size() + 2; @@ -247,7 +262,7 @@ public: for (string &key_val : arg_vec) { auto key = FindField(key_val.data(), NULL, key_delim); auto val = FindField(key_val.data(), key_delim, NULL); - ret.emplace(key,val); + ret.emplace_force(key,val); } return ret; }