mirror of https://gitee.com/bigwinds/arangodb
new simple URI form from endpoint
This commit is contained in:
parent
7d608b160f
commit
0efa889f43
|
@ -73,6 +73,7 @@ inline HttpHandler::status_t RestAgencyHandler::reportUnknownMethod() {
|
|||
|
||||
void RestAgencyHandler::redirectRequest(id_t leaderId) {
|
||||
|
||||
/*
|
||||
std::shared_ptr<Endpoint> 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 () {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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&);
|
||||
|
|
Loading…
Reference in New Issue