管道基础大数据平台系统开发-【后端】-Server
13693261870
2024-03-25 b6b0cb226fcf184525ee7b36af3a09471e9c0057
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 {
@@ -54,8 +60,8 @@
        }
        HttpHost host = this.getTargetHost(url);
        //copyRequestHeaders(request, proxyRequest, host);
        //setXForwardedForHeader(request, proxyRequest);
        // copyRequestHeaders(request, proxyRequest, host);
        //setXrForwardedForHeader(request, proxyRequest);
        if (!StringHelper.isEmpty(cookie)) {
            proxyRequest.addHeader("Cookie", cookie + "; ");
@@ -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);
@@ -94,6 +101,7 @@
        String method = request.getMethod();
        HttpEntityEnclosingRequest proxyRequest = new BasicHttpEntityEnclosingRequest(method, url);
        proxyRequest.setEntity(new InputStreamEntity(request.getInputStream(), getContentLength(request)));
        //String str = EntityUtils.toString(proxyRequest.getEntity(), "UTF-8")
        return proxyRequest;
    }
@@ -118,7 +126,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 +160,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 +200,7 @@
                .setSocketTimeout(-1)
                .build();
        //return HttpClientBuilder.create()
        //                .setDefaultRequestConfig(requestConfig)
        //                .build();
        // return HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build()
        return HttpClients.custom()
                .setDefaultRequestConfig(requestConfig)
                .build();
@@ -246,8 +251,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);
                }
            }
@@ -265,6 +270,7 @@
    protected void copyResponseEntity(HttpResponse proxyResponse, HttpServletResponse response) throws IOException {
        HttpEntity entity = proxyResponse.getEntity();
        if (entity != null) {
            //String str = EntityUtils.toString(entity, "UTF-8")
            OutputStream servletOutputStream = response.getOutputStream();
            entity.writeTo(servletOutputStream);
        }