Add default port method to request API
authorScott Cantor <cantor.2@osu.edu>
Wed, 1 Feb 2012 20:45:59 +0000 (20:45 +0000)
committerScott Cantor <cantor.2@osu.edu>
Wed, 1 Feb 2012 20:45:59 +0000 (20:45 +0000)
xmltooling/io/GenericRequest.h
xmltooling/io/HTTPRequest.cpp
xmltooling/io/HTTPRequest.h

index 11cd82b..7dcb165 100644 (file)
@@ -85,6 +85,13 @@ namespace xmltooling {
         virtual int getPort() const=0;
 
         /**
         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
          * Returns the MIME type of the request, if known.
          *
          * @return the MIME type, or an empty string
index a068a58..b038830 100644 (file)
@@ -51,6 +51,11 @@ GenericRequest::~GenericRequest()
 {
 }
 
 {
 }
 
+bool GenericRequest::isDefaultPort() const
+{
+    return false;
+}
+
 void GenericRequest::setLangDefaults(bool langFromClient, const XMLCh* defaultRange)
 {
     m_langFromClient = langFromClient;
 void GenericRequest::setLangDefaults(bool langFromClient, const XMLCh* defaultRange)
 {
     m_langFromClient = langFromClient;
@@ -184,6 +189,14 @@ bool HTTPRequest::isSecure() const
     return strcmp(getScheme(),"https")==0;
 }
 
     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");
 string HTTPRequest::getLanguageRange() const
 {
     return getHeader("Accept-Language");
index 7cca6c1..e4b2d79 100644 (file)
@@ -55,6 +55,7 @@ namespace xmltooling {
         virtual ~HTTPRequest();
 
         bool isSecure() const;
         virtual ~HTTPRequest();
 
         bool isSecure() const;
+        bool isDefaultPort() const;
         std::string getLanguageRange() const;
           
         /**
         std::string getLanguageRange() const;
           
         /**