From: Scott Cantor Date: Wed, 1 Feb 2012 20:45:59 +0000 (+0000) Subject: Add default port method to request API X-Git-Tag: 1.5.0~33 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=shibboleth%2Fcpp-xmltooling.git;a=commitdiff_plain;h=1401236f23d038cacd275815cb80c1386b112fb6 Add default port method to request API --- diff --git a/xmltooling/io/GenericRequest.h b/xmltooling/io/GenericRequest.h index 11cd82b..7dcb165 100644 --- a/xmltooling/io/GenericRequest.h +++ b/xmltooling/io/GenericRequest.h @@ -85,6 +85,13 @@ namespace xmltooling { virtual int getPort() const=0; /** + * Returns true iff the request port is the default port for the request protocol. + * + * @return default port indicator + */ + virtual bool isDefaultPort() const; + + /** * Returns the MIME type of the request, if known. * * @return the MIME type, or an empty string diff --git a/xmltooling/io/HTTPRequest.cpp b/xmltooling/io/HTTPRequest.cpp index a068a58..b038830 100644 --- a/xmltooling/io/HTTPRequest.cpp +++ b/xmltooling/io/HTTPRequest.cpp @@ -51,6 +51,11 @@ GenericRequest::~GenericRequest() { } +bool GenericRequest::isDefaultPort() const +{ + return false; +} + void GenericRequest::setLangDefaults(bool langFromClient, const XMLCh* defaultRange) { m_langFromClient = langFromClient; @@ -184,6 +189,14 @@ bool HTTPRequest::isSecure() const return strcmp(getScheme(),"https")==0; } +bool HTTPRequest::isDefaultPort() const +{ + if (isSecure()) + return getPort() == 443; + else + return getPort() == 80; +} + string HTTPRequest::getLanguageRange() const { return getHeader("Accept-Language"); diff --git a/xmltooling/io/HTTPRequest.h b/xmltooling/io/HTTPRequest.h index 7cca6c1..e4b2d79 100644 --- a/xmltooling/io/HTTPRequest.h +++ b/xmltooling/io/HTTPRequest.h @@ -55,6 +55,7 @@ namespace xmltooling { virtual ~HTTPRequest(); bool isSecure() const; + bool isDefaultPort() const; std::string getLanguageRange() const; /**