From 796b44ea813a1133beae4f3a67f1c0263510c0c7 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期日, 17 十一月 2024 09:45:07 +0800 Subject: [PATCH] 1 --- src/main/java/com/moon/server/helper/HttpHelper.java | 45 ++++++++++++++++++++++++++++++++++++--------- 1 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/moon/server/helper/HttpHelper.java b/src/main/java/com/moon/server/helper/HttpHelper.java index 6d621d0..b31e8d7 100644 --- a/src/main/java/com/moon/server/helper/HttpHelper.java +++ b/src/main/java/com/moon/server/helper/HttpHelper.java @@ -26,10 +26,7 @@ import java.nio.charset.StandardCharsets; import java.util.Enumeration; -/** - * Http甯姪绫� - * @author WWW - */ +@SuppressWarnings("ALL") public class HttpHelper { private final static String HTTP_SLASH2 = "://"; @@ -69,7 +66,6 @@ CloseableHttpClient client = null; HttpResponse proxyResponse = null; - try { client = this.createHttpClient(); proxyResponse = client.execute(host, proxyRequest); @@ -159,7 +155,6 @@ protected String getRealCookie(String cookieValue) { StringBuilder escapedCookie = new StringBuilder(); - String[] cookies = cookieValue.split("[;,]"); for (String cookie : cookies) { String[] cookieSplit = cookie.split("="); @@ -272,6 +267,10 @@ if (null == entity) { return; } + if (null == res) { + entity.writeTo(response.getOutputStream()); + return; + } switch (res.getCategory()) { case 2: @@ -287,11 +286,39 @@ } private void copeGeoService(HttpResponse proxyResponse, HttpServletRequest request, HttpServletResponse response, ResEntity res) throws IOException { - if (StaticData.GET_CAPABILITIES.equals(request.getParameter(StaticData.REQUEST))) { - // + if (!StaticData.GET_CAPABILITIES.equals(res.getBak())) { + proxyResponse.getEntity().writeTo(response.getOutputStream()); + return; } - proxyResponse.getEntity().writeTo(response.getOutputStream()); + String str = EntityUtils.toString(proxyResponse.getEntity(), "UTF-8"); + String proxyUrl = res.getProxy().replace("{token}", response.getHeader("token")); + proxyUrl = request.getRequestURL().substring(0, request.getRequestURL().indexOf(proxyUrl) + proxyUrl.length()); + str = str.replace(res.getUrl(), proxyUrl); + + int index = str.indexOf(StaticData.QUERYABLE); + while (index > -1) { + int end = str.indexOf("</Layer>", index) + StaticData.I8; + int nameStart = str.indexOf("<Name>", index); + int nameEnd = str.indexOf("</Name>", nameStart); + + String name = ":" + str.substring(nameStart + StaticData.I6, nameEnd); + int idx = res.getTab().indexOf(name); + if (idx > -1) { + int preIdx = res.getTab().lastIndexOf(",", idx) + 1; + String prefix = res.getTab().substring(preIdx, idx); + str = str.substring(0, nameStart + StaticData.I6) + prefix + name + str.substring(nameEnd); + index = str.indexOf(StaticData.QUERYABLE, end); + } else { + end = str.indexOf("<", end); + str = str.substring(0, index) + str.substring(end); + index = str.indexOf(StaticData.QUERYABLE, index); + } + } + + byte[] bytes = str.getBytes(StandardCharsets.UTF_8); + response.setContentLength(bytes.length); + response.getOutputStream().write(bytes); } private void copeSjService(HttpResponse proxyResponse, HttpServletRequest request, HttpServletResponse response, ResEntity res) throws IOException { -- Gitblit v1.9.3