Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow a host to have a path #967

Merged
merged 3 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added

- Recommendation on how to cite in publications (#943)
- Support for URL path in host (#966)

### Changed

Expand Down
1 change: 1 addition & 0 deletions scripts/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ if type clang-format-14 2> /dev/null ; then
elif type clang-format 2> /dev/null ; then
# Clang format found, but need to check version
CLANG_FORMAT=clang-format
V=$(clang-format --version)
jcoupey marked this conversation as resolved.
Show resolved Hide resolved
if [[ $V != *14.0* ]] ; then
echo "clang-format is not 14.0 (returned ${V})"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int main(int argc, char** argv) {
.set_tab_expansion()
.add_options("Solving")
("a,host",
"host for the routing profile",
"host for the routing profile, optionally with a URL path, e.g 'routing.openstreetmap.de/routed-car'",
jcoupey marked this conversation as resolved.
Show resolved Hide resolved
cxxopts::value<std::vector<std::string>>(host_args)->default_value({vroom::DEFAULT_PROFILE + ":0.0.0.0"}))
("c,choose-eta",
"choose ETA for custom routes and report violations",
Expand Down
2 changes: 1 addition & 1 deletion src/routing/ors_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ std::string OrsWrapper::build_query(const std::vector<Location>& locations,
body += "}";

// Building query for ORS
std::string query = "POST /ors/v2/" + service + "/" + profile;
std::string query = "POST /" + _server.path + "ors/v2/" + service + "/" + profile;

query += " HTTP/1.0\r\n";
query += "Accept: */*\r\n";
Expand Down
2 changes: 1 addition & 1 deletion src/routing/osrm_routed_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ OsrmRoutedWrapper::build_query(const std::vector<Location>& locations,
const std::string& service,
const std::string& extra_args) const {
// Building query for osrm-routed
std::string query = "GET /" + service;
std::string query = "GET /" + _server.path + service;

query += "/v1/" + profile + "/";

Expand Down
4 changes: 2 additions & 2 deletions src/routing/valhalla_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ValhallaWrapper::ValhallaWrapper(const std::string& profile,
std::string ValhallaWrapper::get_matrix_query(
const std::vector<Location>& locations) const {
// Building matrix query for Valhalla.
std::string query = "GET /" + _matrix_service + "?json=";
std::string query = "GET /" + _server.path + _matrix_service + "?json=";

// List locations.
std::string all_locations;
Expand All @@ -56,7 +56,7 @@ std::string
ValhallaWrapper::get_route_query(const std::vector<Location>& locations,
const std::string& extra_args) const {
// Building matrix query for Valhalla.
std::string query = "GET /" + _route_service + "?json={\"locations\":[";
std::string query = "GET /" + _server.path + _route_service + "?json={\"locations\":[";

for (auto const& location : locations) {
query += "{\"lon\":" + std::to_string(location.lon()) + "," +
Expand Down
15 changes: 15 additions & 0 deletions src/structures/cl_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void update_host(Servers& servers, const std::string& value) {
// Determine profile and host from a "car:0.0.0.0"-like value.
std::string profile = DEFAULT_PROFILE;
std::string host;
std::string path = "";

auto index = value.find(':');
if (index == std::string::npos) {
Expand All @@ -26,13 +27,27 @@ void update_host(Servers& servers, const std::string& value) {
host = value.substr(index + 1);
}

// remove any trailing slash
if (host.find('/') == host.length() - 1) {
host.pop_back();
}
jcoupey marked this conversation as resolved.
Show resolved Hide resolved

// pull out a path if any and append a trailing slash for query building
index = host.find('/');
if (index != std::string::npos) {
path = host.substr(index + 1) + "/";
jcoupey marked this conversation as resolved.
Show resolved Hide resolved
host = host.substr(0, index);
}

auto existing_profile = servers.find(profile);
if (existing_profile != servers.end()) {
existing_profile->second.host = host;
existing_profile->second.path = path;
} else {
auto add_result = servers.emplace(profile, Server());
assert(add_result.second);
add_result.first->second.host = host;
add_result.first->second.path = path;
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/structures/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ enum class ROUTER { OSRM, LIBOSRM, ORS, VALHALLA };
struct Server {
std::string host;
std::string port;
std::string path;

Server() : host("0.0.0.0"), port("5000") {
Server() : host("0.0.0.0"), port("5000"), path("") {
}

Server(std::string host, std::string port)
: host(std::move(host)), port(std::move(port)) {
: host(std::move(host)), port(std::move(port)), path("") {
}
};

Expand Down