package io.core9.proxy;

import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.TreeMap;

import org.littleshoot.proxy.HostResolver;

public class Core9HostResolver implements HostResolver {
	
	private final Map<String,Proxy> HOSTS = new TreeMap<String,Proxy>();

	@Override
	public InetSocketAddress resolve(String host, int port) throws UnknownHostException {
		if(HOSTS.containsKey(host)) {
			return new InetSocketAddress(HOSTS.get(host).getOrigin(), port);
		} else {
			return null;
		}
	}
	
	public Core9HostResolver addHost(Proxy proxy) {
		HOSTS.put(proxy.getHostname(), proxy);
		return this;
	}
	
	public Core9HostResolver removeHost(String address) {
		HOSTS.remove(address);
		return this;
	}
	
	public Proxy getProxySpecification(String hostname) {
		return HOSTS.get(hostname);
	}
	
	public Core9HostResolver removeAllHosts() {
		HOSTS.clear();
		return this;
	}

}

@@ -444,16 +444,199 @@
 ost)) %7B%0A
+%09%09%09String origin = HOSTS.get(host).getOrigin();%0A%09%09%09if(origin.contains(%22:%22)) %7B%0A%09%09%09%09String %5B%5D temp = origin.split(%22:%22);%0A%09%09%09%09origin = temp%5B0%5D;%0A%09%09%09%09port = Integer.parseInt(temp%5B1%5D);%0A%09%09%09%7D%0A
 %09%09%09retur
@@ -663,35 +663,14 @@
 ess(
-HOSTS.get(host).getO
+o
 rigin
-()
 , po

Support port mappings from origin