Skip to content

A proxy implementation for Vert.x ported from Smiley's HTTP-Proxy-Servlet

License

Notifications You must be signed in to change notification settings

relvaner/vertx-web-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vertx-web-proxy - Example

public class ServerVerticle extends AbstractVerticle {
	@Override
	public void start() throws Exception {
		Router router = Router.router(vertx);
		router.route().handler(CookieHandler.create());
		router.route().handler(BodyHandler.create()
				.setBodyLimit(-1)
				.setDeleteUploadedFilesOnEnd(true));
		
		proxyConfig(router);
		
		vertx.createHttpServer(new HttpServerOptions().setSsl(true).setKeyStoreOptions(
		        new JksOptions().setPath("server-keystore.jks").setPassword("secret")))
			.requestHandler(router)
			.listen(443);
	}
	
	public void proxyConfig(Router router) {
		WebClientOptions options = new WebClientOptions();
		options.setSsl(true);
		WebClient webClient = WebClient.create(vertx, options);
		
		ProxyWebClientOptions proxyOptions = new ProxyWebClientOptions();
		proxyOptions
			.setLog(true);
		
		CircuitBreakerForWebClient circuitBreaker = new CircuitBreakerForWebClient(vertx, 
				new CircuitBreakerOptions()
					.setMaxFailures(3)
					.setTimeout(5_000)
					.setResetTimeout(2_000));
		
		ProxyWebClient proxyWebClient = new ProxyWebClient(webClient, proxyOptions, circuitBreaker);
		
		Map<String, String> targetUris = new HashMap<>();
		targetUris.put("/*", "https://host:port");
		targetUris.put("/apple", "http://host:port");
		targetUris.put("/banana/*", "https://host:port");
			
		ProxyLogger.logger().setLevel(Level.INFO);
		MultiProxyConfig multiProxyConfig = new MultiProxyConfig(proxyWebClient, targetUris);
		multiProxyConfig.config(router);
	}
}

License

This library is released under an open source Apache 2.0 license. Ported with adaptations from Smiley's HTTP Proxy Servlet.

About

A proxy implementation for Vert.x ported from Smiley's HTTP-Proxy-Servlet

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages