use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class ClientConnection method handleResponseEnd.
void handleResponseEnd(LastHttpContent trailer) {
if (metrics.isEnabled()) {
HttpClientRequestBase req = currentResponse.request();
Object reqMetric = req.metric();
if (req.exceptionOccurred != null) {
metrics.requestReset(reqMetric);
} else {
metrics.responseEnd(reqMetric, currentResponse);
}
}
Buffer last = pausedChunk;
pausedChunk = null;
currentResponse.handleEnd(last, new HeadersAdaptor(trailer.trailingHeaders()));
// Also we keep the connection open for an HTTP CONNECT
if (currentResponse.statusCode() != 100 && requestForResponse.method() != io.vertx.core.http.HttpMethod.CONNECT) {
boolean close = false;
// See https://tools.ietf.org/html/rfc7230#section-6.3
String responseConnectionHeader = currentResponse.getHeader(HttpHeaders.Names.CONNECTION);
io.vertx.core.http.HttpVersion protocolVersion = client.getOptions().getProtocolVersion();
String requestConnectionHeader = requestForResponse.headers().get(HttpHeaders.Names.CONNECTION);
// We don't need to protect against concurrent changes on forceClose as it only goes from false -> true
if (HttpHeaders.Values.CLOSE.equalsIgnoreCase(responseConnectionHeader) || HttpHeaders.Values.CLOSE.equalsIgnoreCase(requestConnectionHeader)) {
// In all cases, if we have a close connection option then we SHOULD NOT treat the connection as persistent
close = true;
} else if (protocolVersion == io.vertx.core.http.HttpVersion.HTTP_1_0 && !HttpHeaders.Values.KEEP_ALIVE.equalsIgnoreCase(responseConnectionHeader)) {
// In the HTTP/1.0 case both request/response need a keep-alive connection header the connection to be persistent
// currently Vertx forces the Connection header if keepalive is enabled for 1.0
close = true;
}
if (close) {
pool.responseEnded(this, true);
} else {
if (reset) {
if (requests.isEmpty()) {
pool.responseEnded(this, true);
}
} else {
pool.responseEnded(this, false);
}
}
}
currentResponse = null;
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class StreamsExamples method pump2.
public void pump2(Vertx vertx) {
NetServer server = vertx.createNetServer(new NetServerOptions().setPort(1234).setHost("localhost"));
server.connectHandler(sock -> {
sock.handler(buffer -> {
if (!sock.writeQueueFull()) {
sock.write(buffer);
}
});
}).listen();
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class ConnectionHolder method writeMessage.
// TODO optimise this (contention on monitor)
synchronized void writeMessage(ClusteredMessage message) {
if (connected) {
Buffer data = message.encodeToWire();
metrics.messageWritten(message.address(), data.length());
socket.write(data);
} else {
if (pending == null) {
pending = new ArrayDeque<>();
}
pending.add(message);
}
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class SharedDataExamples method example1.
public void example1(Vertx vertx) {
SharedData sd = vertx.sharedData();
LocalMap<String, String> map1 = sd.getLocalMap("mymap1");
// Strings are immutable so no need to copy
map1.put("foo", "bar");
LocalMap<String, Buffer> map2 = sd.getLocalMap("mymap2");
// This buffer will be copied before adding to map
map2.put("eek", Buffer.buffer().appendInt(123));
// Then... in another part of your application:
map1 = sd.getLocalMap("mymap1");
String val = map1.get("foo");
map2 = sd.getLocalMap("mymap2");
Buffer buff = map2.get("eek");
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class StreamsExamples method pump1.
public void pump1(Vertx vertx) {
NetServer server = vertx.createNetServer(new NetServerOptions().setPort(1234).setHost("localhost"));
server.connectHandler(sock -> {
sock.handler(buffer -> {
sock.write(buffer);
});
}).listen();
}
Aggregations