mirror of
https://github.com/ggerganov/llama.cpp
synced 2026-03-01 21:00:04 +01:00
server: fix query params lost when proxying requests in multi-model router mode (#19854)
* 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
This commit is contained in:
parent
418dea39ce
commit
47eb12b953
@ -339,6 +339,17 @@ static std::map<std::string, std::string> get_headers(const httplib::Request & r
|
|||||||
return headers;
|
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 unique_ptr for request to allow safe capturing in lambdas
|
||||||
using server_http_req_ptr = std::unique_ptr<server_http_req>;
|
using server_http_req_ptr = std::unique_ptr<server_http_req>;
|
||||||
|
|
||||||
@ -382,6 +393,7 @@ void server_http_context::get(const std::string & path, const server_http_contex
|
|||||||
get_params(req),
|
get_params(req),
|
||||||
get_headers(req),
|
get_headers(req),
|
||||||
req.path,
|
req.path,
|
||||||
|
build_query_string(req),
|
||||||
req.body,
|
req.body,
|
||||||
req.is_connection_closed
|
req.is_connection_closed
|
||||||
});
|
});
|
||||||
@ -396,6 +408,7 @@ void server_http_context::post(const std::string & path, const server_http_conte
|
|||||||
get_params(req),
|
get_params(req),
|
||||||
get_headers(req),
|
get_headers(req),
|
||||||
req.path,
|
req.path,
|
||||||
|
build_query_string(req),
|
||||||
req.body,
|
req.body,
|
||||||
req.is_connection_closed
|
req.is_connection_closed
|
||||||
});
|
});
|
||||||
|
|||||||
@ -36,7 +36,8 @@ using server_http_res_ptr = std::unique_ptr<server_http_res>;
|
|||||||
struct server_http_req {
|
struct server_http_req {
|
||||||
std::map<std::string, std::string> params; // path_params + query_params
|
std::map<std::string, std::string> params; // path_params + query_params
|
||||||
std::map<std::string, std::string> headers; // reserved for future use
|
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;
|
std::string body;
|
||||||
const std::function<bool()> & should_stop;
|
const std::function<bool()> & should_stop;
|
||||||
|
|
||||||
|
|||||||
@ -697,11 +697,15 @@ server_http_res_ptr server_models::proxy_request(const server_http_req & req, co
|
|||||||
mapping[name].meta.last_used = ggml_time_ms();
|
mapping[name].meta.last_used = ggml_time_ms();
|
||||||
}
|
}
|
||||||
SRV_INF("proxying request to model %s on port %d\n", name.c_str(), meta->port);
|
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>(
|
auto proxy = std::make_unique<server_http_proxy>(
|
||||||
method,
|
method,
|
||||||
CHILD_ADDR,
|
CHILD_ADDR,
|
||||||
meta->port,
|
meta->port,
|
||||||
req.path,
|
proxy_path,
|
||||||
req.headers,
|
req.headers,
|
||||||
req.body,
|
req.body,
|
||||||
req.should_stop,
|
req.should_stop,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user