Push for proxy test pt 3!

This commit is contained in:
kohlerpop1
2024-01-11 15:14:11 -05:00
committed by Jacek W
parent 2c12b71e99
commit af4f2b4510
5 changed files with 21 additions and 16 deletions

View File

@@ -46,6 +46,7 @@ public class HttpClientSettings {
final Map<String, String> cookies;
@Getter
@Setter
ProxyClientSettings proxyClientSettings;
@Getter
@@ -104,7 +105,7 @@ public class HttpClientSettings {
newSettings.getHeaders().putAll(new TreeMap<>(this.headers));
newSettings.getCookies().putAll(new TreeMap<>(this.cookies));
newSettings.getParams().putAll(new TreeMap<>(this.params));
newSettings.proxyClientSettings = this.proxyClientSettings.clone();
newSettings.proxyClientSettings = this.proxyClientSettings;
return newSettings;
}

View File

@@ -39,8 +39,7 @@ public class ProxyClientSettings implements Iterator<ProxyData>
private int index = 0;
private boolean autoDiscard = true;
private Proxy.Type type = Proxy.Type.DIRECT;
private Consumer<ProxyData> onProxyUpdated = (x)->{};
private Consumer<ProxyData> onProxyUpdated = x -> {};
public boolean addProxy(String addressPort) {
return proxyList.add(ProxyData.map(addressPort));
@@ -66,19 +65,17 @@ public class ProxyClientSettings implements Iterator<ProxyData>
@Override
public ProxyData next()
{
var nextProxy = switch (rotation)
var nextProxy = switch (rotation)
{
case CONSECUTIVE -> {
index = (index+1) % proxyList.size();
yield proxyList.get(index).clone();
yield proxyList.get(index).clone();
}
case RANDOM -> {
index = new Random().nextInt(proxyList.size());
yield proxyList.get(index).clone();
}
default -> {
yield proxyList.get(index).clone();
}
case NONE -> proxyList.get(index).clone();
};
onProxyUpdated.accept(nextProxy);
return nextProxy;
@@ -98,13 +95,14 @@ public class ProxyClientSettings implements Iterator<ProxyData>
this.index = index;
}
}
public ProxyClientSettings clone() {
public ProxyClientSettings clone()
{
ProxyClientSettings settings = new ProxyClientSettings();
settings.setEnabled(enabled);
settings.setRotation(rotation);
settings.setIndex(index);
settings.setType(type);
settings.setOnProxyUpdated(onProxyUpdated);
proxyList.forEach(proxyData -> settings.addProxy(proxyData.getAddress(), proxyData.getPort()));
return settings;
}