package com.sf.vertx.handle;

import io.vertx.circuitbreaker.CircuitBreaker;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.client.WebClient;
import io.vertx.httpproxy.HttpProxy;

/**
 * @author <a href="mailto:emad.albloushi@gmail.com">Emad Alblueshi</a>
 */
public class ProxyHandlerImpl implements ProxyHandler {

	private final HttpProxy httpProxy;
	private WebClient mainWebClient;

	public ProxyHandlerImpl(WebClient mainWebClient, HttpProxy httpProxy) {
		this.httpProxy = httpProxy;
		this.mainWebClient = mainWebClient;
	}

	public ProxyHandlerImpl(HttpProxy httpProxy) {
		this.httpProxy = httpProxy;
	}

	public ProxyHandlerImpl(HttpProxy httpProxy, int port, String host) {
		this.httpProxy = httpProxy.origin(port, host);
	}

	@Override
	public void handle(RoutingContext ctx) {
		// TODO 改造了这个地方
		httpProxy.handle(mainWebClient, ctx);
		// 原始代码只有如下一句
		// httpProxy.handle(ctx.request());
	}
}