From 43c5821d3d2832324114737e62bfbb3b43e64f98 Mon Sep 17 00:00:00 2001 From: qing <1776177662@qq.com> Date: Tue, 4 Aug 2026 21:20:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(gateway):=20=E4=BF=AE=E5=A4=8D=E4=BB=A3?= =?UTF-8?q?=E7=90=86=20URL=20=E5=8F=8C=E6=96=9C=E6=9D=A0=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E4=B8=8B=E6=B8=B8=20404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit handleProxy 拼接转发 URL 时,target_path 以 '/' 开头, url = t_url + '/' + target_path 会产生双斜杠(如 //list)。 core 等使用精确路径匹配的下游服务返回 404。 修复:仅当 target_path 不以 '/' 开头时才补斜杠。 --- gateway/src/main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gateway/src/main.cpp b/gateway/src/main.cpp index 4e1d13c..ce5f6e7 100644 --- a/gateway/src/main.cpp +++ b/gateway/src/main.cpp @@ -2126,7 +2126,10 @@ http::response handleProxy( THROW_EX_CUSTOM(HttpException, 2300, "Invalid request path", 400, "*"); url = t_url; - url += "/"; + /* 避免 target_path 以 "/" 开头时产生双斜杠(如 http://host:port//list), + * 下游服务(core 等)使用精确路径匹配,双斜杠会导致 404 */ + if (target_path.empty() || target_path[0] != '/') + url += "/"; url += target_path; std::string raw = "";