fix(gateway): 修复代理 URL 双斜杠导致下游 404
handleProxy 拼接转发 URL 时,target_path 以 '/' 开头, url = t_url + '/' + target_path 会产生双斜杠(如 //list)。 core 等使用精确路径匹配的下游服务返回 404。 修复:仅当 target_path 不以 '/' 开头时才补斜杠。
This commit is contained in:
1 parent
1d7641cc89
commit
43c5821d3d
1 file changed
+4
-1
@@ -2126,7 +2126,10 @@ http::response<http::string_body> 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 = "";
|
||||
|
||||
Reference in new issue
Block a user