Example usage for io.vertx.core.http HttpServerResponse push

List of usage examples for io.vertx.core.http HttpServerResponse push

Introduction

In this page you can find the example usage for io.vertx.core.http HttpServerResponse push.

Prototype

@Fluent
default HttpServerResponse push(HttpMethod method, String path,
        Handler<AsyncResult<HttpServerResponse>> handler) 

Source Link

Document

Like #push(HttpMethod,String,String,MultiMap,Handler) with the host copied from the current request.

Usage

From source file:examples.HTTP2Examples.java

License:Open Source License

public void example6(HttpServerRequest request) {

    HttpServerResponse response = request.response();

    // Push main.js to the client
    response.push(HttpMethod.GET, "/main.js", ar -> {

        if (ar.succeeded()) {

            // The server is ready to push the response
            HttpServerResponse pushedResponse = ar.result();

            // Send main.js response
            pushedResponse.putHeader("content-type", "application/json").end("alert(\"Push response hello\")");
        } else {/*from   ww  w.  j  a v  a2  s  .  c o  m*/
            System.out.println("Could not push client resource " + ar.cause());
        }
    });

    // Send the requested resource
    response.sendFile("<html><head><script src=\"/main.js\"></script></head><body></body></html>");
}