diff options
| author | shizhendong <[email protected]> | 2021-04-27 14:08:02 +0800 |
|---|---|---|
| committer | shizhendong <[email protected]> | 2021-04-27 14:08:02 +0800 |
| commit | dcde2719b1660938e20e3b4e12b64ceee16cdb98 (patch) | |
| tree | af35ef988ea2401dc80aaffef016d78d4a3508d1 /src | |
| parent | f10718450417328dae6898a420125204bb37a15d (diff) | |
fix: 解决 /prometheus/proxy 代理接口问题
1. /federate url 转码问题
2. HTTP 重复响应头问题
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/net/geedge/confagent/controller/PrometheusController.java | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/main/java/net/geedge/confagent/controller/PrometheusController.java b/src/main/java/net/geedge/confagent/controller/PrometheusController.java index 24c19b9..bcc36e2 100644 --- a/src/main/java/net/geedge/confagent/controller/PrometheusController.java +++ b/src/main/java/net/geedge/confagent/controller/PrometheusController.java @@ -1,8 +1,8 @@ package net.geedge.confagent.controller; import cn.hutool.core.net.url.UrlBuilder; +import cn.hutool.core.net.url.UrlPath; import cn.hutool.core.util.ReflectUtil; -import cn.hutool.core.util.URLUtil; import cn.hutool.http.HttpConnection; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; +import java.nio.charset.Charset; import java.util.*; @RestController @@ -141,8 +142,7 @@ public class PrometheusController extends BaseController{ public void requestProm(String host, int port, String path, HttpServletRequest request, HttpServletResponse response) { String queryString = request.getQueryString(); - String url = UrlBuilder.create().setScheme("http").setHost(host).setPort(port).appendPath(path).toString()+"?"+queryString; - url = URLUtil.decode(url); + String url = UrlBuilder.create().setScheme("http").setHost(host).setPort(port).setPath(UrlPath.of(path, Charset.forName("UTF-8"))).toURL().toString() + "?" + queryString; log.debug("prometheus url: {}", url); String method = request.getMethod(); @@ -177,7 +177,7 @@ public class PrometheusController extends BaseController{ //复制响应头 for(Map.Entry<String, List<String>> en : responseHeaders.entrySet()) { String key = en.getKey(); - if (Tool.StrUtil.isEmpty(key)) continue; + if (Tool.StrUtil.isEmpty(key) || "Transfer-Encoding".equals(key)) continue; List<String> value = en.getValue(); ReflectUtil.invoke(response,"addHeader",key,Tool.StrUtil.join("; ",value)); } |
