* server: fix query params lost when proxying requests in multi-model router mode
* server: re-encode query params using httplib::encode_query_component in proxy
return headers;
}
+static std::string build_query_string(const httplib::Request & req) {
+ std::string qs;
+ for (const auto & [key, value] : req.params) {
+ if (!qs.empty()) {
+ qs += '&';
+ }
+ qs += httplib::encode_query_component(key) + "=" + httplib::encode_query_component(value);
+ }
+ return qs;
+}
+
// using unique_ptr for request to allow safe capturing in lambdas
using server_http_req_ptr = std::unique_ptr<server_http_req>;
get_params(req),
get_headers(req),
req.path,
+ build_query_string(req),
req.body,
req.is_connection_closed
});
get_params(req),
get_headers(req),
req.path,
+ build_query_string(req),
req.body,
req.is_connection_closed
});
struct server_http_req {
std::map<std::string, std::string> params; // path_params + query_params
std::map<std::string, std::string> headers; // reserved for future use
- std::string path; // reserved for future use
+ std::string path;
+ std::string query_string; // query parameters string (e.g. "action=save")
std::string body;
const std::function<bool()> & should_stop;
mapping[name].meta.last_used = ggml_time_ms();
}
SRV_INF("proxying request to model %s on port %d\n", name.c_str(), meta->port);
+ std::string proxy_path = req.path;
+ if (!req.query_string.empty()) {
+ proxy_path += '?' + req.query_string;
+ }
auto proxy = std::make_unique<server_http_proxy>(
method,
CHILD_ADDR,
meta->port,
- req.path,
+ proxy_path,
req.headers,
req.body,
req.should_stop,