diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2020-01-18 15:24:20 +0000 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2020-01-18 15:24:20 +0000 | 
| commit | a2231b799729238636e4c47100d7771ae50d6195 (patch) | |
| tree | fca9304a48ac0d8b16331026d320083c5b46f061 | |
| parent | Performance fixes (diff) | |
| download | icespider-a2231b799729238636e4c47100d7771ae50d6195.tar.bz2 icespider-a2231b799729238636e4c47100d7771ae50d6195.tar.xz icespider-a2231b799729238636e4c47100d7771ae50d6195.zip | |
Helper for testing for HTTPS
| -rw-r--r-- | icespider/core/ihttpRequest.h | 1 | ||||
| -rw-r--r-- | icespider/fcgi/cgiRequestBase.cpp | 7 | ||||
| -rw-r--r-- | icespider/fcgi/cgiRequestBase.h | 1 | ||||
| -rw-r--r-- | icespider/testing/testRequest.cpp | 6 | ||||
| -rw-r--r-- | icespider/testing/testRequest.h | 1 | ||||
| -rw-r--r-- | icespider/unittests/testFcgi.cpp | 9 | 
6 files changed, 25 insertions, 0 deletions
| diff --git a/icespider/core/ihttpRequest.h b/icespider/core/ihttpRequest.h index e1044f1..a8eee28 100644 --- a/icespider/core/ihttpRequest.h +++ b/icespider/core/ihttpRequest.h @@ -33,6 +33,7 @@ namespace IceSpider {  			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 bool isSecure() const = 0;  			static Accepted parseAccept(const std::string_view &);  			virtual Slicer::DeserializerPtr getDeserializer() const;  			virtual ContentTypeSerializer getSerializer(const IRouteHandler *) const; diff --git a/icespider/fcgi/cgiRequestBase.cpp b/icespider/fcgi/cgiRequestBase.cpp index b6d5a77..8e04c07 100644 --- a/icespider/fcgi/cgiRequestBase.cpp +++ b/icespider/fcgi/cgiRequestBase.cpp @@ -19,6 +19,7 @@ namespace IceSpider {  	constexpr std::string_view amp("&");  	constexpr std::string_view semi("; ");  	constexpr std::string_view HEADER_PREFIX("HTTP_"); +	constexpr std::string_view HTTPS("HTTPS");  	CGI_CONST(REDIRECT_URL);  	CGI_CONST(SCRIPT_NAME);  	CGI_CONST(QUERY_STRING); @@ -165,6 +166,12 @@ namespace IceSpider {  		return optionalLookup(key, envmap);  	} +	bool +	CgiRequestBase::isSecure() const +	{ +		return envmap.find(HTTPS) != envmap.end(); +	} +  	OptionalString  	CgiRequestBase::getHeaderParam(const std::string_view & key) const  	{ diff --git a/icespider/fcgi/cgiRequestBase.h b/icespider/fcgi/cgiRequestBase.h index 88bc473..f235acf 100644 --- a/icespider/fcgi/cgiRequestBase.h +++ b/icespider/fcgi/cgiRequestBase.h @@ -24,6 +24,7 @@ namespace IceSpider {  			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; +			bool isSecure() const override;  			void response(short, const std::string_view &) const override;  			void setHeader(const std::string_view &, const std::string_view &) const override; diff --git a/icespider/testing/testRequest.cpp b/icespider/testing/testRequest.cpp index 080c07e..fea77f2 100644 --- a/icespider/testing/testRequest.cpp +++ b/icespider/testing/testRequest.cpp @@ -42,6 +42,12 @@ namespace IceSpider {  		return get(key, env);  	} +	bool +	TestRequest::isSecure() const +	{ +		return env.find("HTTPS") != env.end(); +	} +  	OptionalString  	TestRequest::getQueryStringParam(const std::string_view & key) const  	{ diff --git a/icespider/testing/testRequest.h b/icespider/testing/testRequest.h index a08f9c0..31d3e4b 100644 --- a/icespider/testing/testRequest.h +++ b/icespider/testing/testRequest.h @@ -18,6 +18,7 @@ namespace IceSpider {  			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; +			bool isSecure() 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 &); diff --git a/icespider/unittests/testFcgi.cpp b/icespider/unittests/testFcgi.cpp index c77edeb..c7b239e 100644 --- a/icespider/unittests/testFcgi.cpp +++ b/icespider/unittests/testFcgi.cpp @@ -127,6 +127,15 @@ BOOST_AUTO_TEST_CASE( script_name_root )  	CharPtrPtrArray env ({ "SCRIPT_NAME=/" });  	TestRequest r(this, env);  	BOOST_REQUIRE(r.getRequestPath().empty()); +	BOOST_CHECK(!r.isSecure()); +} + +BOOST_AUTO_TEST_CASE( script_name_root_https ) +{ +	CharPtrPtrArray env ({ "SCRIPT_NAME=/", "HTTPS=on" }); +	TestRequest r(this, env); +	BOOST_REQUIRE(r.getRequestPath().empty()); +	BOOST_CHECK(r.isSecure());  }  BOOST_AUTO_TEST_CASE( redirect_uri_root ) | 
