<commit_before>package com.x.server.console.server.web;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.jetty.proxy.AsyncProxyServlet;

public class Proxy extends AsyncProxyServlet {

	private static final long serialVersionUID = 2737360000716631564L;

	@Override
	protected String rewriteTarget(HttpServletRequest request) {
		String url = request.getRequestURL().toString();
		String parameter = request.getQueryString();
		return target(url, parameter, this.getServletConfig().getInitParameter("port"));
	}

	private String target(String url, String parameter, String port) {
		int x = StringUtils.indexOf(url, ":", 8);
		int y = StringUtils.indexOf(url, "/", 8);
		if ((x > 0) && (y > 0)) {
			return url.substring(0, x) + port(url, port) + url.substring(y)
					+ (StringUtils.isBlank(parameter) ? "" : "?" + parameter);
		} else if (y > 0) {
			return url.substring(0, y) + port(url, port) + url.substring(y)
					+ (StringUtils.isBlank(parameter) ? "" : "?" + parameter);
		} else {
			return null;
		}
	}

	private String port(String url, String port) {
		if (StringUtils.startsWithIgnoreCase(url, "https://") || StringUtils.startsWithIgnoreCase(url, "wss://")) {
			if (StringUtils.equals(port, "443")) {
				return "";
			}
		} else if (StringUtils.startsWithIgnoreCase(url, "http://") || StringUtils.startsWithIgnoreCase(url, "ws://")) {
			if (StringUtils.equals(port, "80")) {
				return "";
			}
		}
		return ":" + port;
	}

}<commit_msg>修改代理到本地127,0,0,1<commit_after>package com.x.server.console.server.web;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.proxy.AsyncProxyServlet;

public class Proxy extends AsyncProxyServlet {

	private static final long serialVersionUID = 2737360000716631564L;
	private static final String X_Real_IP = "X-Real-IP";

	@Override
	protected String rewriteTarget(HttpServletRequest request) {
		String url = request.getRequestURL().toString();
		String parameter = request.getQueryString();
		return target(url, parameter, this.getServletConfig().getInitParameter("port"));
	}

	private String target(String url, String parameter, String port) {
		int x = StringUtils.indexOf(url, "://");
		int y = StringUtils.indexOf(url, "/", 8);
		if ((x > 0) && (y > 0)) {
			return url.substring(0, x + 3) + "127.0.0.1" + port(url, port) + url.substring(y)
					+ (StringUtils.isBlank(parameter) ? "" : "?" + parameter);
		} else {
			return null;
		}
	}

//	private String target(String url, String parameter, String port) {
//		int x = StringUtils.indexOf(url, ":", 8);
//		int y = StringUtils.indexOf(url, "/", 8);
//		if ((x > 0) && (y > 0)) {
//			return url.substring(0, x) + port(url, port) + url.substring(y)
//					+ (StringUtils.isBlank(parameter) ? "" : "?" + parameter);
//		} else if (y > 0) {
//			return url.substring(0, y) + port(url, port) + url.substring(y)
//					+ (StringUtils.isBlank(parameter) ? "" : "?" + parameter);
//		} else {
//			return null;
//		}
//	}

	private String port(String url, String port) {
		if (StringUtils.startsWithIgnoreCase(url, "https://") || StringUtils.startsWithIgnoreCase(url, "wss://")) {
			if (StringUtils.equals(port, "443")) {
				return "";
			}
		} else if (StringUtils.startsWithIgnoreCase(url, "http://") || StringUtils.startsWithIgnoreCase(url, "ws://")) {
			if (StringUtils.equals(port, "80")) {
				return "";
			}
		}
		return ":" + port;
	}

	@Override
	protected void addXForwardedHeaders(HttpServletRequest clientRequest, Request proxyRequest) {
		if (StringUtils.isNotEmpty(clientRequest.getHeader(HttpHeader.X_FORWARDED_FOR.asString()))) {
			proxyRequest.header(HttpHeader.X_FORWARDED_FOR,
					clientRequest.getHeader(HttpHeader.X_FORWARDED_FOR.asString()));
		} else {
			proxyRequest.header(HttpHeader.X_FORWARDED_FOR, clientRequest.getRemoteAddr());
		}
		if (StringUtils.isNotEmpty(clientRequest.getHeader(HttpHeader.X_FORWARDED_PROTO.asString()))) {
			proxyRequest.header(HttpHeader.X_FORWARDED_PROTO,
					clientRequest.getHeader(HttpHeader.X_FORWARDED_PROTO.asString()));
		} else {
			proxyRequest.header(HttpHeader.X_FORWARDED_PROTO, clientRequest.getScheme());
		}
		if (StringUtils.isNotEmpty(clientRequest.getHeader(HttpHeader.X_FORWARDED_HOST.asString()))) {
			proxyRequest.header(HttpHeader.X_FORWARDED_HOST,
					clientRequest.getHeader(HttpHeader.X_FORWARDED_HOST.asString()));
		} else {
			proxyRequest.header(HttpHeader.X_FORWARDED_HOST, clientRequest.getHeader(HttpHeader.HOST.asString()));
		}
		if (StringUtils.isNotEmpty(clientRequest.getHeader(HttpHeader.X_FORWARDED_SERVER.asString()))) {
			proxyRequest.header(HttpHeader.X_FORWARDED_SERVER,
					clientRequest.getHeader(HttpHeader.X_FORWARDED_SERVER.asString()));
		} else {
			proxyRequest.header(HttpHeader.X_FORWARDED_SERVER, clientRequest.getLocalName());
		}

		if (StringUtils.isNotEmpty(clientRequest.getHeader(HttpHeader.HOST.asString()))) {
			proxyRequest.header(HttpHeader.HOST, clientRequest.getHeader(HttpHeader.HOST.asString()));
		}

		if (StringUtils.isNotEmpty(clientRequest.getHeader(X_Real_IP))) {
			proxyRequest.header(X_Real_IP, clientRequest.getHeader(X_Real_IP));
		} else {
			proxyRequest.header(X_Real_IP, clientRequest.getRemoteAddr());
		}

//		if (StringUtils.isNotEmpty(clientRequest.getHeader(HttpHeader.UPGRADE.asString()))) {
//			proxyRequest.header(HttpHeader.UPGRADE, clientRequest.getHeader(HttpHeader.UPGRADE.asString()));
//		}
//
//		if (StringUtils.isNotEmpty(clientRequest.getHeader(HttpHeader.CONNECTION.asString()))) {
//			proxyRequest.header(HttpHeader.CONNECTION, clientRequest.getHeader(HttpHeader.CONNECTION.asString()));
//		}
//
//		if (StringUtils.isNotEmpty(clientRequest.getHeader(HttpHeader.SEC_WEBSOCKET_EXTENSIONS.asString()))) {
//			proxyRequest.header(HttpHeader.SEC_WEBSOCKET_EXTENSIONS,
//					clientRequest.getHeader(HttpHeader.SEC_WEBSOCKET_EXTENSIONS.asString()));
//		}
//
//		if (StringUtils.isNotEmpty(clientRequest.getHeader(HttpHeader.SEC_WEBSOCKET_KEY.asString()))) {
//			proxyRequest.header(HttpHeader.SEC_WEBSOCKET_KEY,
//					clientRequest.getHeader(HttpHeader.SEC_WEBSOCKET_KEY.asString()));
//		}

		if (StringUtils.isNotEmpty(clientRequest.getHeader(HttpHeader.SEC_WEBSOCKET_VERSION.asString()))) {
			proxyRequest.header(HttpHeader.SEC_WEBSOCKET_VERSION,
					clientRequest.getHeader(HttpHeader.SEC_WEBSOCKET_VERSION.asString()));
		}

	}

}
{'fraction_non_alphanumeric': 0.1518677281077771, 'fraction_numerical': 0.012400489895897121, 'mean_word_length': 4.928312159709619, 'pattern_counts': {'":': 5, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6543486', 'n_tokens_mistral': 2408, 'n_tokens_neox': 2194, 'n_words': 319}