From 8260695b46c6a60f8aba312ca1fbd97b224aa662 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 22 Jan 2019 21:00:36 +0000 Subject: HTTP headers are case insensitive --- icespider/fcgi/cgiRequestBase.cpp | 18 +++++++----------- icespider/fcgi/cgiRequestBase.h | 10 +++++++--- icespider/unittests/testFcgi.cpp | 1 + 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/icespider/fcgi/cgiRequestBase.cpp b/icespider/fcgi/cgiRequestBase.cpp index 5bcb746..6acaa38 100644 --- a/icespider/fcgi/cgiRequestBase.cpp +++ b/icespider/fcgi/cgiRequestBase.cpp @@ -70,6 +70,11 @@ namespace IceSpider { return i->second; } + bool CgiRequestBase::ciLess::operator() (const std::string_view & s1, const std::string_view & s2) const + { + return lexicographical_compare(s1, s2, ba::is_iless()); + } + void CgiRequestBase::initialize() { @@ -113,18 +118,9 @@ namespace IceSpider { return s; } + template OptionalString - CgiRequestBase::optionalLookup(const std::string_view & key, const VarMap & vm) - { - auto i = vm.find(key); - if (i == vm.end()) { - return {}; - } - return i->second; - } - - OptionalString - CgiRequestBase::optionalLookup(const std::string_view & key, const StringMap & vm) + CgiRequestBase::optionalLookup(const std::string_view & key, const MapType & vm) { auto i = vm.find(key); if (i == vm.end()) { diff --git a/icespider/fcgi/cgiRequestBase.h b/icespider/fcgi/cgiRequestBase.h index 6b430b7..fca2e41 100644 --- a/icespider/fcgi/cgiRequestBase.h +++ b/icespider/fcgi/cgiRequestBase.h @@ -14,7 +14,11 @@ namespace IceSpider { void initialize(); public: + struct ciLess { + bool operator()(const std::string_view & s1, const std::string_view & s2) const; + }; typedef std::map VarMap; + typedef std::map HdrMap; const PathElements & getRequestPath() const override; PathElements & getRequestPath() override; @@ -30,13 +34,13 @@ namespace IceSpider { std::ostream & dump(std::ostream & s) const override; private: - static OptionalString optionalLookup(const std::string_view & key, const VarMap &); - static OptionalString optionalLookup(const std::string_view & key, const StringMap &); + template + static OptionalString optionalLookup(const std::string_view & key, const MapType &); VarMap envmap; StringMap qsmap; StringMap cookiemap; - VarMap hdrmap; + HdrMap hdrmap; PathElements pathElements; }; } diff --git a/icespider/unittests/testFcgi.cpp b/icespider/unittests/testFcgi.cpp index adaaaff..b64dd47 100644 --- a/icespider/unittests/testFcgi.cpp +++ b/icespider/unittests/testFcgi.cpp @@ -232,6 +232,7 @@ BOOST_AUTO_TEST_CASE( acceptheader ) CharPtrPtrArray env ({ "SCRIPT_NAME=/", "HTTP_ACCEPT=text/html" }); TestRequest r(this, env); BOOST_REQUIRE_EQUAL("text/html", *r.getHeaderParam("ACCEPT")); + BOOST_REQUIRE_EQUAL("text/html", *r.getHeaderParam(IceSpider::H::ACCEPT)); } BOOST_AUTO_TEST_CASE( missingheader ) -- cgit v1.2.3