use of io.vertx.core.http.HttpClientOptions in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
HttpClientRequest req = vertx.createHttpClient(new HttpClientOptions()).put(8080, "localhost", "/someurl", resp -> {
System.out.println("Response " + resp.statusCode());
});
String filename = "upload.txt";
FileSystem fs = vertx.fileSystem();
fs.props(filename, ares -> {
FileProps props = ares.result();
System.out.println("props is " + props);
long size = props.size();
req.headers().set("content-length", "" + size);
fs.open(filename, new OpenOptions(), ares2 -> {
AsyncFile file = ares2.result();
Pump pump = Pump.pump(file, req);
file.endHandler(v -> {
req.end();
});
pump.start();
});
});
}
use of io.vertx.core.http.HttpClientOptions in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
HttpClientOptions options = new HttpClientOptions().setProtocolVersion(HttpVersion.HTTP_2);
vertx.createHttpClient(options).getNow(8080, "localhost", "/", resp -> {
System.out.println("Got response " + resp.statusCode() + " with protocol " + resp.version());
resp.bodyHandler(body -> System.out.println("Got data " + body.toString("ISO-8859-1")));
});
}
use of io.vertx.core.http.HttpClientOptions in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
// Note! in real-life you wouldn't often set trust all to true as it could leave you open to man in the middle attacks.
HttpClientOptions options = new HttpClientOptions().setSsl(true).setUseAlpn(true).setProtocolVersion(HttpVersion.HTTP_2).setTrustAll(true);
HttpClient client = vertx.createHttpClient(options);
HttpClientRequest request = client.get(8443, "localhost", "/", resp -> {
System.out.println("Got response " + resp.statusCode() + " with protocol " + resp.version());
resp.bodyHandler(body -> System.out.println("Got data " + body.toString("ISO-8859-1")));
});
// Set handler for server side push
request.pushHandler(pushedReq -> {
System.out.println("Receiving pushed content");
pushedReq.handler(pushedResp -> {
pushedResp.bodyHandler(body -> System.out.println("Got pushed data " + body.toString("ISO-8859-1")));
});
});
request.end();
}
use of io.vertx.core.http.HttpClientOptions in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
HttpClientRequest request = vertx.createHttpClient(new HttpClientOptions()).put(8080, "localhost", "/", resp -> {
System.out.println("Got response " + resp.statusCode());
resp.bodyHandler(body -> System.out.println("Got data " + body.toString("ISO-8859-1")));
});
request.setChunked(true);
for (int i = 0; i < 10; i++) {
request.write("client-chunk-" + i);
}
request.end();
}
use of io.vertx.core.http.HttpClientOptions in project vertx-examples by vert-x3.
the class Proxy method start.
@Override
public void start() throws Exception {
HttpClient client = vertx.createHttpClient(new HttpClientOptions());
vertx.createHttpServer().requestHandler(req -> {
System.out.println("Proxying request: " + req.uri());
HttpClientRequest c_req = client.request(req.method(), 8282, "localhost", req.uri(), c_res -> {
System.out.println("Proxying response: " + c_res.statusCode());
req.response().setChunked(true);
req.response().setStatusCode(c_res.statusCode());
req.response().headers().setAll(c_res.headers());
c_res.handler(data -> {
System.out.println("Proxying response body: " + data.toString("ISO-8859-1"));
req.response().write(data);
});
c_res.endHandler((v) -> req.response().end());
});
c_req.setChunked(true);
c_req.headers().setAll(req.headers());
req.handler(data -> {
System.out.println("Proxying request body " + data.toString("ISO-8859-1"));
c_req.write(data);
});
req.endHandler((v) -> c_req.end());
}).listen(8080);
}
Aggregations