diff --git a/server/controller/src/main/java/ai/starwhale/mlops/common/proxy/WebServerInTask.java b/server/controller/src/main/java/ai/starwhale/mlops/common/proxy/WebServerInTask.java index 7ec253549e..63b753ec54 100644 --- a/server/controller/src/main/java/ai/starwhale/mlops/common/proxy/WebServerInTask.java +++ b/server/controller/src/main/java/ai/starwhale/mlops/common/proxy/WebServerInTask.java @@ -71,7 +71,7 @@ public String generateGatewayUrl(Long taskId, String taskIp, int port) { if (featuresProperties.isJobProxyEnabled()) { return String.format(TASK_GATEWAY_PATTERN, taskId, port); } else { - return String.format("http://%s/%d", taskIp, port); + return String.format("http://%s:%d", taskIp, port); } } } diff --git a/server/controller/src/main/java/ai/starwhale/mlops/configuration/security/ProjectNameExtractorDataStoreMixed.java b/server/controller/src/main/java/ai/starwhale/mlops/configuration/security/ProjectNameExtractorDataStoreMixed.java index 90c359a082..ba7af39e77 100644 --- a/server/controller/src/main/java/ai/starwhale/mlops/configuration/security/ProjectNameExtractorDataStoreMixed.java +++ b/server/controller/src/main/java/ai/starwhale/mlops/configuration/security/ProjectNameExtractorDataStoreMixed.java @@ -138,26 +138,7 @@ boolean isDataStore(HttpServletRequest request) { public static String SYSTEM_PROJECT = "0"; private Set projectsOfNoneDataStore(HttpServletRequest request) { - // this filter only works for project parameter in url or parameter - // we assume that no project parameter in post body - // and read project parameter from post body will interfere with the getInputStream() method, - // so we return empty set here if the request is a post request with form data or www-form-urlencoded - var method = request.getMethod(); - var contentType = request.getContentType(); - if ("POST".equalsIgnoreCase(method) - && (contentType.contains("form-data") || contentType.contains("www-form-urlencoded"))) { - return Set.of(); - } - - String projectUrl = request.getParameter("project"); - if (!StrUtil.isEmpty(projectUrl)) { - return Set.of(projectUrl); - } - projectUrl = request.getParameter("projectUrl"); - if (!StrUtil.isEmpty(projectUrl)) { - return Set.of(projectUrl); - } - projectUrl = HttpUtil.getResourceUrlFromPath(request.getRequestURI(), Resources.PROJECT); + var projectUrl = HttpUtil.getResourceUrlFromPath(request.getRequestURI(), Resources.PROJECT); if (!StrUtil.isEmpty(projectUrl)) { return Set.of(URLDecoder.decode(projectUrl, Charset.defaultCharset())); } diff --git a/server/controller/src/test/java/ai/starwhale/mlops/common/proxy/WebServerInTaskTest.java b/server/controller/src/test/java/ai/starwhale/mlops/common/proxy/WebServerInTaskTest.java index 0d9a2edeaf..952a58df01 100644 --- a/server/controller/src/test/java/ai/starwhale/mlops/common/proxy/WebServerInTaskTest.java +++ b/server/controller/src/test/java/ai/starwhale/mlops/common/proxy/WebServerInTaskTest.java @@ -65,4 +65,15 @@ void getTarget() { var target = webServerInTask.getTarget(successUri); assertEquals("http://1.2.3.4:8765/foo", target); } + + @Test + void testGenerateGatewayUrl() { + when(featuresProperties.isJobProxyEnabled()).thenReturn(true); + var gatewayUrl = webServerInTask.generateGatewayUrl(1L, "1.1.1.1", 2); + assertEquals("/gateway/task/1/2/", gatewayUrl); + + when(featuresProperties.isJobProxyEnabled()).thenReturn(false); + gatewayUrl = webServerInTask.generateGatewayUrl(1L, "1.1.1.1", 2); + assertEquals("http://1.1.1.1:2", gatewayUrl); + } }