diff --git a/arangod/RestHandler/RestAgencyHandler.cpp b/arangod/RestHandler/RestAgencyHandler.cpp index dc274d6134..992929882a 100644 --- a/arangod/RestHandler/RestAgencyHandler.cpp +++ b/arangod/RestHandler/RestAgencyHandler.cpp @@ -73,6 +73,7 @@ inline HttpHandler::status_t RestAgencyHandler::reportUnknownMethod() { void RestAgencyHandler::redirectRequest(id_t leaderId) { + /* std::shared_ptr ep ( Endpoint::clientFactory (_agent->config().end_points.at(leaderId))); std::stringstream url; @@ -82,10 +83,13 @@ void RestAgencyHandler::redirectRequest(id_t leaderId) { url << "s"; } url << ep->hostAndPort() << _request->requestPath(); + */ + + std::string url = Endpoint::uriForm(_agent->config().end_points.at(leaderId)); createResponse(GeneralResponse::ResponseCode::TEMPORARY_REDIRECT); static std::string const location = "location"; - _response->setHeaderNC(location, url.str()); + _response->setHeaderNC(location, url); } HttpHandler::status_t RestAgencyHandler::handleStores () { diff --git a/lib/Endpoint/Endpoint.cpp b/lib/Endpoint/Endpoint.cpp index 092be6acfc..e60c0dec26 100644 --- a/lib/Endpoint/Endpoint.cpp +++ b/lib/Endpoint/Endpoint.cpp @@ -51,6 +51,27 @@ Endpoint::Endpoint(DomainType domainType, EndpointType type, TRI_invalidatesocket(&_socket); } + +std::string Endpoint::uriForm (std::string const& endpoint) { + + std::stringstream url; + size_t const prefix_len = 6; + + if (StringUtils::isPrefix(endpoint, "tcp://")) { + url << "http://"; + } else if (StringUtils::isPrefix(endpoint, "ssl://")) { + url << "https://"; + } else { + throw arangodb::basics::Exception ( + 0, std::string("malformed URL ") + endpoint + + ". Support only for ssl:// and tcp:// endpoints." , __FILE__, __LINE__); + } + + url << endpoint.substr(prefix_len,endpoint.size()+1-(prefix_len+1)); + + return url.str(); + +} //////////////////////////////////////////////////////////////////////////////// /// @brief return the endpoint specification in a unified form //////////////////////////////////////////////////////////////////////////////// @@ -68,9 +89,9 @@ std::string Endpoint::unifiedForm(std::string const& specification) { std::string copy = StringUtils::tolower(specification); StringUtils::trimInPlace(copy); - if (specification[specification.size() - 1] == '/') { + if (specification.back() == '/') { // address ends with a slash => remove - copy = copy.substr(0, copy.size() - 1); + copy.pop_back(); } // read protocol from string diff --git a/lib/Endpoint/Endpoint.h b/lib/Endpoint/Endpoint.h index 3e63d5acf1..d0c73c4f08 100644 --- a/lib/Endpoint/Endpoint.h +++ b/lib/Endpoint/Endpoint.h @@ -52,6 +52,7 @@ class Endpoint { virtual ~Endpoint() {} public: + static std::string uriForm(std::string const&); static std::string unifiedForm(std::string const&); static Endpoint* serverFactory(std::string const&, int, bool reuseAddress); static Endpoint* clientFactory(std::string const&);