/* * Copyright (c) 2019-2020. Developed by Hedgecode. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.hedgecode.chess.scanner.proxy; import org.hedgecode.chess.scanner.proxy.client.HttpRequestClient; import org.hedgecode.chess.scanner.proxy.client.SocksRequestClient; import org.hedgecode.chess.scanner.proxy.system.SystemProxy; import org.hedgecode.chess.scanner.request.PlainRequestClient; import org.hedgecode.chess.scanner.request.RequestClient; /** * Proxy settings main class. * * @author Dmitry Samoshin aka gotty */ public final class Proxy { private static Proxy proxy; private RequestClient requestClient; private Proxy() { requestClient = new PlainRequestClient(); } public static void setProxy(ProxyParams proxyParams) { getProxy().set(proxyParams); } public static RequestClient getRequestClient() { return getProxy().client(); } private void set(ProxyParams proxyParams) { if (proxyParams.isSystem()) { SystemProxy.setProxy(proxyParams); requestClient = new PlainRequestClient(); } else { switch (proxyParams.getType()) { case HTTP: requestClient = new HttpRequestClient(proxyParams); break; case SOCKS: requestClient = new SocksRequestClient(proxyParams); break; default: requestClient = new PlainRequestClient(); } } } private RequestClient client() { return requestClient; } private static Proxy getProxy() { if (proxy == null) { proxy = new Proxy(); } return proxy; } }