Example usage for io.vertx.core.http HttpClient redirectHandler

List of usage examples for io.vertx.core.http HttpClient redirectHandler

Introduction

In this page you can find the example usage for io.vertx.core.http HttpClient redirectHandler.

Prototype

@Fluent
HttpClient redirectHandler(Function<HttpClientResponse, Future<HttpClientRequest>> handler);

Source Link

Document

Set a redirect handler for the http client.

Usage

From source file:examples.HTTPExamples.java

License:Open Source License

public void exampleFollowRedirect03(HttpClient client) {

    client.redirectHandler(response -> {

        // Only follow 301 code
        if (response.statusCode() == 301 && response.getHeader("Location") != null) {

            // Compute the redirect URI
            String absoluteURI = resolveURI(response.request().absoluteURI(), response.getHeader("Location"));

            // Create a new ready to use request that the client will use
            return Future.succeededFuture(client.getAbs(absoluteURI));
        }/*from w  ww.  ja  v  a  2s.c o m*/

        // We don't redirect
        return null;
    });
}