From 917763c435c91bdf2cd3f0f109de39e7bc8e8586 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Wed, 17 Jul 2019 14:50:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dhttp=E5=A4=B4=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/Parser.h | 14 +++++++++----- src/Http/HttpSession.cpp | 9 ++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Common/Parser.h b/src/Common/Parser.h index fdbdc8f2..bfe2ceed 100644 --- a/src/Common/Parser.h +++ b/src/Common/Parser.h @@ -16,7 +16,9 @@ namespace mediakit{ string FindField(const char *buf, const char *start, const char *end, int bufSize = 0); struct StrCaseCompare { - bool operator()(const string &__x, const string &__y) const { return strcasecmp(__x.data(), __y.data()) < 0; } + bool operator()(const string &__x, const string &__y) const { + return strcasecmp(__x.data(), __y.data()) < 0; + } }; @@ -25,17 +27,19 @@ class StrCaseMap : public multimap{ typedef multimap Super ; StrCaseMap() = default; ~StrCaseMap() = default; - string &operator[](const string &key){ - auto it = find(key); + + template + string &operator[](K &&k){ + auto it = find(std::forward(k)); if(it == end()){ - it = Super::emplace(key,""); + it = Super::emplace(std::forward(k),""); } return it->second; } template void emplace(K &&k , V &&v) { - auto it = find(k); + auto it = find(std::forward(k)); if(it != end()){ return; } diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index 938b24c7..ed015e50 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -913,13 +913,16 @@ void HttpSession::responseDelay(const string &Origin,bool bClose, sendNotFound(bClose); return; } - auto headerOther=makeHttpHeader(bClose,contentOut.size(),"text/plain"); + auto headerOther = makeHttpHeader(bClose,contentOut.size(),"text/plain"); if(!Origin.empty()){ headerOther["Access-Control-Allow-Origin"] = Origin; headerOther["Access-Control-Allow-Credentials"] = "true"; } - const_cast(headerOut).insert(headerOther.begin(), headerOther.end()); - sendResponse(codeOut.data(), headerOut, contentOut); + for (auto &pr : headerOut){ + //替换掉默认的http头 + headerOther[pr.first] = pr.second; + } + sendResponse(codeOut.data(), headerOther, contentOut); } inline void HttpSession::sendNotFound(bool bClose) { GET_CONFIG(string,notFound,Http::kNotFound);