diff options
-rw-r--r-- | icespider/common/http.ice | 3 | ||||
-rw-r--r-- | icespider/common/session.ice | 1 | ||||
-rw-r--r-- | icespider/core/ihttpRequest.cpp | 22 | ||||
-rw-r--r-- | icespider/core/ihttpRequest.h | 26 | ||||
-rw-r--r-- | icespider/fcgi/cgiRequestBase.cpp | 19 | ||||
-rw-r--r-- | icespider/fcgi/cgiRequestBase.h | 14 | ||||
-rw-r--r-- | icespider/testing/testRequest.cpp | 34 | ||||
-rw-r--r-- | icespider/testing/testRequest.h | 28 | ||||
-rw-r--r-- | icespider/unittests/testFileSessions.cpp | 2 |
9 files changed, 78 insertions, 71 deletions
diff --git a/icespider/common/http.ice b/icespider/common/http.ice index 72e1de7..1b51da7 100644 --- a/icespider/common/http.ice +++ b/icespider/common/http.ice @@ -31,7 +31,8 @@ module IceSpider { float q = 1.0; }; - ["slicer:json:object"] + ["slicer:json:object", + "cpp:type:std::map<std::string, std::string, std::less<>>"] local dictionary<string, string> StringMap; module S { // Statuses diff --git a/icespider/common/session.ice b/icespider/common/session.ice index 37c0c9b..d4136fa 100644 --- a/icespider/common/session.ice +++ b/icespider/common/session.ice @@ -3,6 +3,7 @@ [["ice-prefix"]] module IceSpider { + ["cpp:type:std::map<std::string, std::string, std::less<>>"] dictionary<string, string> Variables; exception SessionError { diff --git a/icespider/core/ihttpRequest.cpp b/icespider/core/ihttpRequest.cpp index 6afa124..7df6084 100644 --- a/icespider/core/ihttpRequest.cpp +++ b/icespider/core/ihttpRequest.cpp @@ -98,7 +98,7 @@ namespace IceSpider { // Set-Cookie: value[; expires=date][; domain=domain][; path=path][; secure] // Sat, 02 May 2009 23:38:25 GMT - void IHttpRequest::setCookie(const std::string & name, const std::string & value, + void IHttpRequest::setCookie(const std::string_view & name, const std::string_view & value, const Ice::optional<std::string> & d, const Ice::optional<std::string> & p, bool s, Ice::optional<time_t> e) { @@ -126,7 +126,7 @@ namespace IceSpider { return Ice::optional<T>(); } - void IHttpRequest::responseRedirect(const std::string & url, const Ice::optional<std::string> & statusMsg) const + void IHttpRequest::responseRedirect(const std::string_view & url, const Ice::optional<std::string> & statusMsg) const { setHeader(H::LOCATION, url); response(303, (statusMsg ? *statusMsg : S::MOVED)); @@ -142,25 +142,27 @@ namespace IceSpider { } #define getParams(T) \ - template<> void IHttpRequest::setCookie<T>(const std::string & n, const T & v, \ + template<> void IHttpRequest::setCookie<T>(const std::string_view & n, const T & v, \ const Ice::optional<std::string> & d, const Ice::optional<std::string> & p, \ bool s, Ice::optional<time_t> e) { \ - setCookie(n, boost::lexical_cast<std::string>(v), d, p, s, e); } \ + auto vs = boost::lexical_cast<std::string>(v); \ + setCookie(n, std::string_view(vs), d, p, s, e); \ + } \ template<> T IHttpRequest::getURLParam<T>(unsigned int idx) const { \ return wrapLexicalCast<T>(getURLParam(idx)); } \ - template<> Ice::optional<T> IHttpRequest::getQueryStringParam<T>(const std::string & key) const { \ + template<> Ice::optional<T> IHttpRequest::getQueryStringParam<T>(const std::string_view & key) const { \ return optionalLexicalCast<T>(getQueryStringParam(key)); } \ - template<> Ice::optional<T> IHttpRequest::getCookieParam<T>(const std::string & key) const { \ + template<> Ice::optional<T> IHttpRequest::getCookieParam<T>(const std::string_view & key) const { \ return optionalLexicalCast<T>(getCookieParam(key)); } \ - template<> Ice::optional<T> IHttpRequest::getHeaderParam<T>(const std::string & key) const { \ + template<> Ice::optional<T> IHttpRequest::getHeaderParam<T>(const std::string_view & key) const { \ return optionalLexicalCast<T>(getHeaderParam(key)); } template<> std::string IHttpRequest::getURLParam<std::string>(unsigned int idx) const { return getURLParam(idx); } - template<> Ice::optional<std::string> IHttpRequest::getQueryStringParam<std::string>(const std::string & key) const { \ + template<> Ice::optional<std::string> IHttpRequest::getQueryStringParam<std::string>(const std::string_view & key) const { \ return getQueryStringParam(key); } - template<> Ice::optional<std::string> IHttpRequest::getCookieParam<std::string>(const std::string & key) const { \ + template<> Ice::optional<std::string> IHttpRequest::getCookieParam<std::string>(const std::string_view & key) const { \ return getCookieParam(key); } - template<> Ice::optional<std::string> IHttpRequest::getHeaderParam<std::string>(const std::string & key) const { \ + template<> Ice::optional<std::string> IHttpRequest::getHeaderParam<std::string>(const std::string_view & key) const { \ return getHeaderParam(key); } getParams(bool); diff --git a/icespider/core/ihttpRequest.h b/icespider/core/ihttpRequest.h index e255886..6e3be55 100644 --- a/icespider/core/ihttpRequest.h +++ b/icespider/core/ihttpRequest.h @@ -28,15 +28,15 @@ namespace IceSpider { virtual HttpMethod getRequestMethod() const = 0; const std::string & getURLParam(unsigned int) const; - virtual OptionalString getQueryStringParam(const std::string &) const = 0; - virtual OptionalString getHeaderParam(const std::string &) const = 0; - virtual OptionalString getCookieParam(const std::string &) const = 0; - virtual OptionalString getEnv(const std::string &) const = 0; + virtual OptionalString getQueryStringParam(const std::string_view &) const = 0; + virtual OptionalString getHeaderParam(const std::string_view &) const = 0; + virtual OptionalString getCookieParam(const std::string_view &) const = 0; + virtual OptionalString getEnv(const std::string_view &) const = 0; virtual Slicer::DeserializerPtr getDeserializer() const; virtual ContentTypeSerializer getSerializer(const IRouteHandler *) const; virtual std::istream & getInputStream() const = 0; virtual std::ostream & getOutputStream() const = 0; - virtual void setHeader(const std::string &, const std::string &) const = 0; + virtual void setHeader(const std::string_view &, const std::string_view &) const = 0; virtual std::ostream & dump(std::ostream & s) const = 0; @@ -48,7 +48,7 @@ namespace IceSpider { return Slicer::DeserializeAnyWith<T>(getDeserializer()); } template<typename T> - Ice::optional<T> getBodyParam(const Ice::optional<IceSpider::StringMap> & map, const std::string & key) const + Ice::optional<T> getBodyParam(const Ice::optional<IceSpider::StringMap> & map, const std::string_view & key) const { if (!map) { return Ice::optional<T>(); @@ -61,20 +61,20 @@ namespace IceSpider { return boost::lexical_cast<T>(i->second); } } - void responseRedirect(const std::string & url, const Ice::optional<std::string> & = IceUtil::None) const; - void setCookie(const std::string &, const std::string &, + void responseRedirect(const std::string_view & url, const Ice::optional<std::string> & = IceUtil::None) const; + void setCookie(const std::string_view &, const std::string_view &, const Ice::optional<std::string> & = IceUtil::None, const Ice::optional<std::string> & = IceUtil::None, bool = false, Ice::optional<time_t> = IceUtil::None); template<typename T> - void setCookie(const std::string &, const T &, const Ice::optional<std::string> & = IceUtil::None, + void setCookie(const std::string_view &, const T &, const Ice::optional<std::string> & = IceUtil::None, const Ice::optional<std::string> & = IceUtil::None, bool = false, Ice::optional<time_t> = IceUtil::None); template<typename T> - Ice::optional<T> getQueryStringParam(const std::string & key) const; + Ice::optional<T> getQueryStringParam(const std::string_view & key) const; template<typename T> - Ice::optional<T> getHeaderParam(const std::string & key) const; + Ice::optional<T> getHeaderParam(const std::string_view & key) const; template<typename T> - Ice::optional<T> getCookieParam(const std::string & key) const; - virtual void response(short, const std::string &) const = 0; + Ice::optional<T> getCookieParam(const std::string_view & key) const; + virtual void response(short, const std::string_view &) const = 0; template<typename T> void response(const IRouteHandler * route, const T & t) const { diff --git a/icespider/fcgi/cgiRequestBase.cpp b/icespider/fcgi/cgiRequestBase.cpp index 96ec1b4..a42a78f 100644 --- a/icespider/fcgi/cgiRequestBase.cpp +++ b/icespider/fcgi/cgiRequestBase.cpp @@ -125,7 +125,7 @@ namespace IceSpider { } OptionalString - CgiRequestBase::optionalLookup(const std::string & key, const StringMap & vm) + CgiRequestBase::optionalLookup(const std::string_view & key, const StringMap & vm) { auto i = vm.find(key); if (i == vm.end()) { @@ -159,36 +159,39 @@ namespace IceSpider { } OptionalString - CgiRequestBase::getQueryStringParam(const std::string & key) const + CgiRequestBase::getQueryStringParam(const std::string_view & key) const { return optionalLookup(key, qsmap); } OptionalString - CgiRequestBase::getCookieParam(const std::string & key) const + CgiRequestBase::getCookieParam(const std::string_view & key) const { return optionalLookup(key, cookiemap); } OptionalString - CgiRequestBase::getEnv(const std::string & key) const + CgiRequestBase::getEnv(const std::string_view & key) const { return optionalLookup(key, envmap); } OptionalString - CgiRequestBase::getHeaderParam(const std::string & key) const + CgiRequestBase::getHeaderParam(const std::string_view & key) const { - return optionalLookup(HEADER_PREFIX + boost::algorithm::to_upper_copy(key), envmap); + // TODO: Fix this mess + std::string ks(key); + boost::algorithm::to_upper(ks); + return optionalLookup(HEADER_PREFIX + ks, envmap); } - void CgiRequestBase::response(short statusCode, const std::string & statusMsg) const + void CgiRequestBase::response(short statusCode, const std::string_view & statusMsg) const { StatusFmt::write(getOutputStream(), statusCode, statusMsg); } void - CgiRequestBase::setHeader(const std::string & header, const std::string & value) const + CgiRequestBase::setHeader(const std::string_view & header, const std::string_view & value) const { HdrFmt::write(getOutputStream(), header, value); } diff --git a/icespider/fcgi/cgiRequestBase.h b/icespider/fcgi/cgiRequestBase.h index 0caf23f..efe2746 100644 --- a/icespider/fcgi/cgiRequestBase.h +++ b/icespider/fcgi/cgiRequestBase.h @@ -20,19 +20,19 @@ namespace IceSpider { const PathElements & getRequestPath() const override; PathElements & getRequestPath() override; HttpMethod getRequestMethod() const override; - OptionalString getQueryStringParam(const std::string & key) const override; - OptionalString getHeaderParam(const std::string & key) const override; - OptionalString getCookieParam(const std::string & key) const override; - OptionalString getEnv(const std::string & key) const override; + OptionalString getQueryStringParam(const std::string_view & key) const override; + OptionalString getHeaderParam(const std::string_view & key) const override; + OptionalString getCookieParam(const std::string_view & key) const override; + OptionalString getEnv(const std::string_view & key) const override; - void response(short, const std::string &) const override; - void setHeader(const std::string &, const std::string &) const override; + void response(short, const std::string_view &) const override; + void setHeader(const std::string_view &, const std::string_view &) const override; 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 & key, const StringMap &); + static OptionalString optionalLookup(const std::string_view & key, const StringMap &); VarMap envmap; StringMap qsmap; diff --git a/icespider/testing/testRequest.cpp b/icespider/testing/testRequest.cpp index c7fe4d3..11fd721 100644 --- a/icespider/testing/testRequest.cpp +++ b/icespider/testing/testRequest.cpp @@ -4,7 +4,7 @@ #include <formatters.h> namespace IceSpider { - TestRequest::TestRequest(const Core * c, HttpMethod m, const std::string & p) : + TestRequest::TestRequest(const Core * c, HttpMethod m, const std::string_view & p) : IHttpRequest(c), method(m) { @@ -34,31 +34,31 @@ namespace IceSpider { } OptionalString - TestRequest::getEnv(const std::string & key) const + TestRequest::getEnv(const std::string_view & key) const { return get(key, env); } OptionalString - TestRequest::getQueryStringParam(const std::string & key) const + TestRequest::getQueryStringParam(const std::string_view & key) const { return get(key, qs); } OptionalString - TestRequest::getCookieParam(const std::string & key) const + TestRequest::getCookieParam(const std::string_view & key) const { return get(key, cookies); } OptionalString - TestRequest::getHeaderParam(const std::string & key) const + TestRequest::getHeaderParam(const std::string_view & key) const { return get(key, hdr); } OptionalString - TestRequest::get(const std::string & key, const MapVars & vars) const + TestRequest::get(const std::string_view & key, const MapVars & vars) const { auto i = vars.find(key); if (i == vars.end()) { @@ -68,36 +68,36 @@ namespace IceSpider { } void - TestRequest::setQueryStringParam(const std::string & key, const OptionalString & val) + TestRequest::setQueryStringParam(const std::string_view & key, const OptionalString & val) { set(key, val, qs); } void - TestRequest::setHeaderParam(const std::string & key, const OptionalString & val) + TestRequest::setHeaderParam(const std::string_view & key, const OptionalString & val) { set(key, val, hdr); } - + void - TestRequest::setCookieParam(const std::string & key, const OptionalString & val) + TestRequest::setCookieParam(const std::string_view & key, const OptionalString & val) { set(key, val, cookies); } void - TestRequest::setEnv(const std::string & key, const OptionalString & val) + TestRequest::setEnv(const std::string_view & key, const OptionalString & val) { set(key, val, env); } - + void - TestRequest::set(const std::string & key, const OptionalString & val, MapVars & vars) + TestRequest::set(const std::string_view & key, const OptionalString & val, MapVars & vars) { if (val) - vars[key] = *val; + vars[std::string(key)] = *val; else - vars.erase(key); + vars.erase(vars.find(key)); } std::istream & @@ -113,13 +113,13 @@ namespace IceSpider { } void - TestRequest::response(short statusCode, const std::string & statusMsg) const + TestRequest::response(short statusCode, const std::string_view & statusMsg) const { StatusFmt::write(getOutputStream(), statusCode, statusMsg); } void - TestRequest::setHeader(const std::string & header, const std::string & value) const + TestRequest::setHeader(const std::string_view & header, const std::string_view & value) const { HdrFmt::write(getOutputStream(), header, value); } diff --git a/icespider/testing/testRequest.h b/icespider/testing/testRequest.h index aa0ed67..a08f9c0 100644 --- a/icespider/testing/testRequest.h +++ b/icespider/testing/testRequest.h @@ -7,25 +7,25 @@ namespace IceSpider { class DLL_PUBLIC TestRequest : public IHttpRequest { public: - typedef std::map<std::string, std::string> MapVars; + typedef std::map<std::string, std::string, std::less<>> MapVars; - TestRequest(const Core * c, HttpMethod m, const std::string & p); + TestRequest(const Core * c, HttpMethod m, const std::string_view & p); const PathElements & getRequestPath() const override; PathElements & getRequestPath() override; HttpMethod getRequestMethod() const override; - OptionalString getEnv(const std::string & key) const override; - OptionalString getQueryStringParam(const std::string & key) const override; - OptionalString getCookieParam(const std::string & key) const override; - OptionalString getHeaderParam(const std::string & key) const override; - void setQueryStringParam(const std::string &, const OptionalString &); - void setHeaderParam(const std::string &, const OptionalString &); - void setCookieParam(const std::string &, const OptionalString &); - void setEnv(const std::string &, const OptionalString &); + OptionalString getEnv(const std::string_view & key) const override; + OptionalString getQueryStringParam(const std::string_view & key) const override; + OptionalString getCookieParam(const std::string_view & key) const override; + OptionalString getHeaderParam(const std::string_view & key) const override; + void setQueryStringParam(const std::string_view &, const OptionalString &); + void setHeaderParam(const std::string_view &, const OptionalString &); + void setCookieParam(const std::string_view &, const OptionalString &); + void setEnv(const std::string_view &, const OptionalString &); std::istream & getInputStream() const override; std::ostream & getOutputStream() const override; - void response(short statusCode, const std::string & statusMsg) const override; - void setHeader(const std::string & header, const std::string & value) const override; + void response(short statusCode, const std::string_view & statusMsg) const override; + void setHeader(const std::string_view & header, const std::string_view & value) const override; std::ostream & dump(std::ostream & s) const override; const MapVars & getResponseHeaders(); @@ -40,8 +40,8 @@ namespace IceSpider { const HttpMethod method; protected: - OptionalString get(const std::string &, const MapVars &) const; - void set(const std::string &, const OptionalString &, MapVars &); + OptionalString get(const std::string_view &, const MapVars &) const; + void set(const std::string_view &, const OptionalString &, MapVars &); private: MapVars responseHeaders; diff --git a/icespider/unittests/testFileSessions.cpp b/icespider/unittests/testFileSessions.cpp index c632a34..119586e 100644 --- a/icespider/unittests/testFileSessions.cpp +++ b/icespider/unittests/testFileSessions.cpp @@ -7,7 +7,7 @@ #include <core.h> #include <definedDirs.h> -BOOST_TEST_DONT_PRINT_LOG_VALUE(IceSpider::StringMap); +BOOST_TEST_DONT_PRINT_LOG_VALUE(IceSpider::Variables); class TestCore : public IceSpider::CoreWithDefaultRouter { public: |