From 4b5c7b13f0ebd44c05b50ef8c3e56b0d02bfc4fe Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 12 Jul 2018 15:28:32 +0300 Subject: Use 'builds' parameter instead of 'pn' for ?builds handler --- mod/mod-builds.cxx | 15 ++++++++++++--- mod/mod-repository-root.cxx | 23 ++++++++++++++++------- mod/options.cli | 16 +++++++++++++++- 3 files changed, 43 insertions(+), 11 deletions(-) (limited to 'mod') diff --git a/mod/mod-builds.cxx b/mod/mod-builds.cxx index f255b25..19d187c 100644 --- a/mod/mod-builds.cxx +++ b/mod/mod-builds.cxx @@ -285,6 +285,11 @@ handle (request& rq, response& rs) throw invalid_request (400, e.what ()); } + // Override the name parameter for the old URL (see options.cli for details). + // + if (params.name_legacy_specified ()) + params.name (params.name_legacy ()); + const char* title ("Builds"); xml::serializer s (rs.content (), title); @@ -358,10 +363,9 @@ handle (request& rq, response& rs) // query part. // s << FORM - << *INPUT(TYPE="hidden", NAME="builds") << TABLE(ID="filter", CLASS="proplist") << TBODY - << TR_INPUT ("name", "pn", params.name (), "*", true) + << TR_INPUT ("name", "builds", params.name (), "*", true) << TR_INPUT ("version", "pv", params.version (), "*") << TR_SELECT ("toolchain", "tc", ctc, toolchain_opts) @@ -827,6 +831,12 @@ handle (request& rq, response& rs) string u (root.string () + "?builds"); + if (!params.name ().empty ()) + { + u += '='; + u += mime_url_encode (params.name ()); + } + auto add_filter = [&u] (const char* pn, const string& pv, const char* def = "") @@ -840,7 +850,6 @@ handle (request& rq, response& rs) } }; - add_filter ("pn", params.name ()); add_filter ("pv", params.version ()); add_filter ("tc", params.toolchain (), "*"); add_filter ("cf", params.configuration ()); diff --git a/mod/mod-repository-root.cxx b/mod/mod-repository-root.cxx index 367b137..27901d7 100644 --- a/mod/mod-repository-root.cxx +++ b/mod/mod-repository-root.cxx @@ -28,8 +28,11 @@ using namespace brep::cli; namespace brep { - // Request proxy. Removes the first parameter that is assumed to be a - // function name. + // Request proxy. + // + // Removes the first parameter, that is assumed to be a function name, if its + // value is not present. Otherwise, considers it as the handler's "default" + // parameter value and renames the parameter to "_". // class request_proxy: public request { @@ -45,9 +48,15 @@ namespace brep if (!parameters_ || url_only < url_only_parameters_) { parameters_ = request_.parameters (limit, url_only); - assert (!parameters_->empty ()); // Always starts with a function name. - parameters_->erase (parameters_->begin ()); + + auto i (parameters_->begin ()); + removed_ = !i->value; + + if (removed_) + parameters_->erase (i); + else + i->name = "_"; url_only_parameters_ = url_only; } @@ -58,10 +67,9 @@ namespace brep istream& open_upload (size_t index) { - // The original request object still contains the function name entry, - // so we shift the index. + // Shift the index if the function name parameter was removed. // - return request_.open_upload (index + 1); + return request_.open_upload (index + (removed_ ? 1 : 0)); } istream& @@ -88,6 +96,7 @@ namespace brep request& request_; optional parameters_; bool url_only_parameters_; // Meaningless if parameters_ is not present. + bool removed_ = false; // If the function name parameter was removed. }; // repository_root diff --git a/mod/options.cli b/mod/options.cli index 97453a7..62a339d 100644 --- a/mod/options.cli +++ b/mod/options.cli @@ -572,7 +572,21 @@ namespace brep // Package name wildcard. An empty value is treated the same way as *. // - string name | pn; + // We used to generate URLs like: + // + // https://cppget.org/?builds&pn=bbot + // + // This looked a bit verbose, so now we produce URLs like: + // + // https://cppget.org/?builds=bbot + // + // To support the already distributed URLs the name_legacy (pn) parameter + // overrides the name (builds) parameter, if present. Note that the + // builds parameter is renamed to '_' by the root handler (see the + // request_proxy class for details). + // + string name | _; + string name_legacy | pn; // Package version. If empty or *, then no version constraint is applied. // Otherwise the build package version must match the value exactly. -- cgit v1.1