Factor absolutize method back into xmltooling
authorScott Cantor <cantor.2@osu.edu>
Thu, 2 Feb 2012 04:46:00 +0000 (04:46 +0000)
committerScott Cantor <cantor.2@osu.edu>
Thu, 2 Feb 2012 04:46:00 +0000 (04:46 +0000)
xmltooling/io/GenericRequest.h
xmltooling/io/HTTPRequest.cpp
xmltooling/io/HTTPRequest.h

index 7dcb165..ff24bdb 100644 (file)
@@ -172,6 +172,13 @@ namespace xmltooling {
             getClientCertificates() const=0;
 
         /**
+         * Converts a relative URL into an absolute one based on the properties of the request.
+         *
+         * @param url   input URL to convert, will be modified in place
+         */
+        virtual void absolutize(std::string& url) const;
+
+        /**
          * Returns a language range to use in selecting language-specific
          * content for this request.
          * <p>The syntax is that of the HTTP 1.1 Accept-Language header, even
index b038830..5d897a9 100644 (file)
@@ -56,6 +56,20 @@ 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;
index e4b2d79..d7e95c4 100644 (file)
@@ -29,9 +29,6 @@
 
 #include <xmltooling/io/GenericRequest.h>
 
-#include <map>
-#include <string>
-
 namespace xmltooling {
 
 #if defined (_MSC_VER)