From b1e59a93f4af829250d32f41f5474e041cda517f Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 28 九月 2022 14:11:11 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/helper/HttpHelper.java | 24 ++++++++++++++---------- 1 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/lf/server/helper/HttpHelper.java b/src/main/java/com/lf/server/helper/HttpHelper.java index 5367a6b..70616a4 100644 --- a/src/main/java/com/lf/server/helper/HttpHelper.java +++ b/src/main/java/com/lf/server/helper/HttpHelper.java @@ -29,6 +29,12 @@ * @author WWW */ public class HttpHelper { + private final static String HTTP_SLASH2 = "://"; + + private final static String HTTP_SLASH = "/"; + + private final static Integer THREE = 3; + protected static final HeaderGroup HOP_HEADERS; static { @@ -69,7 +75,8 @@ proxyResponse = client.execute(host, proxyRequest); int statusCode = proxyResponse.getStatusLine().getStatusCode(); - response.setStatus(statusCode); // response.setStatus(statusCode, proxyResponse.getStatusLine().getReasonPhrase()); + // response.setStatus(statusCode, proxyResponse.getStatusLine().getReasonPhrase()) + response.setStatus(statusCode); copyResponseHeaders(proxyResponse, request, response, url); @@ -118,7 +125,7 @@ } protected void copyRequestHeader(HttpServletRequest request, HttpRequest proxyRequest, HttpHost host, String headerName) { - if (headerName.equalsIgnoreCase(HttpHeaders.CONTENT_LENGTH)||HOP_HEADERS.containsHeader(headerName)) { + if (headerName.equalsIgnoreCase(HttpHeaders.CONTENT_LENGTH) || HOP_HEADERS.containsHeader(headerName)) { return; } @@ -152,9 +159,9 @@ protected String getRealCookie(String cookieValue) { StringBuilder escapedCookie = new StringBuilder(); - String cookies[] = cookieValue.split("[;,]"); + String[] cookies = cookieValue.split("[;,]"); for (String cookie : cookies) { - String cookieSplit[] = cookie.split("="); + String[] cookieSplit = cookie.split("="); if (cookieSplit.length == 2) { String cookieName = cookieSplit[0].trim(); if (cookieName.startsWith(cookieName)) { @@ -192,10 +199,7 @@ .setSocketTimeout(-1) .build(); - //return HttpClientBuilder.create() - // .setDefaultRequestConfig(requestConfig) - // .build(); - + // return HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build() return HttpClients.custom() .setDefaultRequestConfig(requestConfig) .build(); @@ -246,8 +250,8 @@ StringBuffer curUrl = request.getRequestURL(); int pos; - if ((pos = curUrl.indexOf("://")) >= 0) { - if ((pos = curUrl.indexOf("/", pos + 3)) >= 0) { + if ((pos = curUrl.indexOf(HTTP_SLASH2)) >= 0) { + if ((pos = curUrl.indexOf(HTTP_SLASH, pos + THREE)) >= 0) { curUrl.setLength(pos); } } -- Gitblit v1.9.3