src/main/java/com/findupon/commons/netops/ChloeHttpRequestExecutor.java
/**
	 * Insert proxy headers on HTTPS requests.
	 * HTTPS requests with custom headers are difficult because the actual request headers are encrypted.
	 * The only point at which unencrypted data is sent to the proxy server is with the initial CONNECT method.
	 * When a client {@link RequestMeta} triggers a session switch,
	 * {@link com.findupon.commons.netops.strategies.ChloeConnectionReuseStrategy} will ensure that connection will is not
	 * persistent in the pool, thus forcing the initial CONNECT to trigger where we can assign a new IP. This has to happen
	 * twice - first to return the new assigned IP from the proxy and second to set our custom headers from their response.
	 * This is handled with {@link ChloeHttpRequestExecutor#processProxyIpResponse(HttpResponse, HttpContext, RequestMeta)}.
	 */
Insert proxy headers on HTTPS requests.
HTTPS requests with custom headers are difficult because the actual request headers are encrypted.
The only point at which unencrypted data is sent to the proxy server is with the initial CONNECT method.
When a client  RequestMeta triggers a session switch,
com.findupon.commons.netops.strategies.ChloeConnectionReuseStrategy will ensure that connection will is not
persistent in the pool, thus forcing the initial CONNECT to trigger where we can assign a new IP. This has to happen
twice - first to return the new assigned IP from the proxy and second to set our custom headers from their response.
Insert proxy headers on HTTPS requests . HTTPS requests with custom headers are difficult because the actual request headers are encrypted . The only point at which unencrypted data is sent to the proxy server is with the initial CONNECT method . When a client RequestMeta triggers a session switch com . findupon . commons . netops . strategies . ChloeConnectionReuseStrategy will ensure that connection will is not persistent in the pool thus forcing the initial CONNECT to trigger where we can assign a new IP . This has to happen twice - first to return the new assigned IP from the proxy and second to set our custom headers from their response .
@Override
	public void preProcess(HttpRequest request, HttpProcessor processor, HttpContext context) throws IOException, HttpException {
		RequestMeta requestMeta = (RequestMeta)context.getAttribute(ContextOps.CTX_AGENT_REQUEST_META);
		if("CONNECT".equalsIgnoreCase(request.getRequestLine().getMethod())) {
			if(requestMeta.proxyUsed()) {
				if(requestMeta.getProxyIp() != null) {
					logger.debug("[ChloeHttpRequestExecutor] - Initial HTTPS CONNECT, setting IP proxy header. IP [{}] Host [{}]", requestMeta.getProxyIp(), requestMeta.getHost());
					request.setHeader(proxySetIpRequestHeader, requestMeta.getProxyIp());
				}
				if(ProxyMode.ROTATE_OPEN.equals(requestMeta.getProxyMode())) {
					logger.debug("[ChloeHttpRequestExecutor] - Initial HTTPS CONNECT, setting country and timeout headers. Host [{}]", requestMeta.getHost());
					request.setHeader(proxyCountryRequestHeader, Locale.US.getCountry());
					request.setHeader(proxyTimeoutRequestHeader, String.valueOf(RequestHelper.getConnectTimeoutSeconds()));
				}
			}
		}
		super.preProcess(request, processor, context);
	}
@ Override public void preProcess ( HttpRequest request , HttpProcessor processor , HttpContext context ) throws IOException , HttpException { RequestMeta requestMeta = ( RequestMeta ) context . getAttribute ( ContextOps . CTX_AGENT_REQUEST_META ) ; if ( "CONNECT" . equalsIgnoreCase ( request . getRequestLine ( ) . getMethod ( ) ) ) { if ( requestMeta . proxyUsed ( ) ) { if ( requestMeta . getProxyIp ( ) != null ) { logger . debug ( "[ChloeHttpRequestExecutor] - Initial HTTPS CONNECT, setting IP proxy header. IP [{}] Host [{}]" , requestMeta . getProxyIp ( ) , requestMeta . getHost ( ) ) ; request . setHeader ( proxySetIpRequestHeader , requestMeta . getProxyIp ( ) ) ; } if ( ProxyMode . ROTATE_OPEN . equals ( requestMeta . getProxyMode ( ) ) ) { logger . debug ( "[ChloeHttpRequestExecutor] - Initial HTTPS CONNECT, setting country and timeout headers. Host [{}]" , requestMeta . getHost ( ) ) ; request . setHeader ( proxyCountryRequestHeader , Locale . US . getCountry ( ) ) ; request . setHeader ( proxyTimeoutRequestHeader , String . valueOf ( RequestHelper . getConnectTimeoutSeconds ( ) ) ) ; } } } super . preProcess ( request , processor , context ) ; }
Insert proxy headers on HTTPS requests.
Insert proxy headers on HTTPS requests .