Factor absolutize method back into xmltooling
[shibboleth/xmltooling.git] / xmltooling / io / HTTPRequest.cpp
index a068a58..5d897a9 100644 (file)
@@ -51,6 +51,25 @@ GenericRequest::~GenericRequest()
 {
 }
 
+bool GenericRequest::isDefaultPort() const
+{
+    return false;
+}
+
+void GenericRequest::absolutize(string& url) const
+{
+    if (url.empty())
+        url = '/';
+    if (url[0] == '/') {
+        // Compute a URL to the root of the site.
+        const char* scheme = getScheme();
+        string root = string(scheme) + "://" + getHostname();
+        if (!isDefaultPort())
+            root += ":" + lexical_cast<string>(getPort());
+        url = root + url;
+    }
+}
+
 void GenericRequest::setLangDefaults(bool langFromClient, const XMLCh* defaultRange)
 {
     m_langFromClient = langFromClient;
@@ -184,6 +203,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");