From 77e5b4a0c86ca26246584bc90342cde8303d0040 Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Thu, 2 Feb 2012 04:46:00 +0000 Subject: [PATCH] Factor absolutize method back into xmltooling --- xmltooling/io/GenericRequest.h | 7 +++++++ xmltooling/io/HTTPRequest.cpp | 14 ++++++++++++++ xmltooling/io/HTTPRequest.h | 3 --- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/xmltooling/io/GenericRequest.h b/xmltooling/io/GenericRequest.h index 7dcb165..ff24bdb 100644 --- a/xmltooling/io/GenericRequest.h +++ b/xmltooling/io/GenericRequest.h @@ -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. *

The syntax is that of the HTTP 1.1 Accept-Language header, even diff --git a/xmltooling/io/HTTPRequest.cpp b/xmltooling/io/HTTPRequest.cpp index b038830..5d897a9 100644 --- a/xmltooling/io/HTTPRequest.cpp +++ b/xmltooling/io/HTTPRequest.cpp @@ -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(getPort()); + url = root + url; + } +} + void GenericRequest::setLangDefaults(bool langFromClient, const XMLCh* defaultRange) { m_langFromClient = langFromClient; diff --git a/xmltooling/io/HTTPRequest.h b/xmltooling/io/HTTPRequest.h index e4b2d79..d7e95c4 100644 --- a/xmltooling/io/HTTPRequest.h +++ b/xmltooling/io/HTTPRequest.h @@ -29,9 +29,6 @@ #include -#include -#include - namespace xmltooling { #if defined (_MSC_VER) -- 2.1.4