com.jetdrone.vertx.yoke.middleware.RequestProxy Maven / Gradle / Ivy
/**
* Copyright 2011-2014 the original author or authors.
*/
package com.jetdrone.vertx.yoke.middleware;
import com.jetdrone.vertx.yoke.Middleware;
import org.jetbrains.annotations.NotNull;
import org.vertx.java.core.Handler;
import org.vertx.java.core.http.HttpClient;
import org.vertx.java.core.VoidHandler;
import org.vertx.java.core.buffer.Buffer;
import org.vertx.java.core.http.HttpClientRequest;
import org.vertx.java.core.http.HttpClientResponse;
/** # RequestProxy
*
* RequestProxy provides web client a simple way to interact with other REST service
* providers via Yoke, meanwhile Yoke could pre-handle authentication, logging and etc.
*
* In order to handler the proxy request properly, Bodyparser should be disabled for the
* path matched by RequestProxy.
*/
public class RequestProxy extends Middleware {
private final String prefix;
private final String host;
private final int port;
private final boolean secure;
public RequestProxy(@NotNull final String prefix, @NotNull final String host, final int port, final boolean secure) {
this.prefix = prefix;
this.host = host;
this.port = port;
this.secure = secure;
}
public RequestProxy(@NotNull final String prefix, final int port, final boolean secure) {
this(prefix, "localhost", port, secure);
}
@Override
public void handle(@NotNull final YokeRequest req, @NotNull final Handler