use of io.vertx.core.http.impl.headers.HeadersAdaptor in project vert.x by eclipse.
the class WebSocketHandshakeInboundHandler method channelRead.
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
if (msg instanceof HttpResponse) {
HttpResponse resp = (HttpResponse) msg;
response = new DefaultFullHttpResponse(resp.protocolVersion(), resp.status());
response.headers().add(resp.headers());
}
if (msg instanceof HttpContent) {
HttpContent content = (HttpContent) msg;
try {
if (response != null) {
response.content().writeBytes(content.content());
if (msg instanceof LastHttpContent) {
response.trailingHeaders().add(((LastHttpContent) msg).trailingHeaders());
ChannelPipeline pipeline = chctx.pipeline();
pipeline.remove(WebSocketHandshakeInboundHandler.this);
ChannelHandler handler = pipeline.get(HttpContentDecompressor.class);
if (handler != null) {
// remove decompressor as its not needed anymore once connection was upgraded to WebSocket
ctx.pipeline().remove(handler);
}
Future<HeadersAdaptor> fut = handshakeComplete(response);
wsHandler.handle(fut);
}
}
} finally {
content.release();
}
}
}
use of io.vertx.core.http.impl.headers.HeadersAdaptor in project vert.x by eclipse.
the class HeadersTestBase method testSetAllOnExistingMapUsingMultiMapHttp1.
@Test
public void testSetAllOnExistingMapUsingMultiMapHttp1() {
MultiMap mainMap = new HeadersAdaptor(HeadersMultiMap.httpHeaders());
mainMap.add("originalKey", "originalValue");
MultiMap setAllMap = newMultiMap();
setAllMap.add("originalKey", "newValue");
setAllMap.add("anotherKey", "anotherValue");
MultiMap result = mainMap.setAll(setAllMap);
assertNotNull(result);
assertFalse(result.isEmpty());
assertEquals(2, result.size());
assertEquals("newValue", result.get("originalKey"));
assertEquals("anotherValue", result.get("anotherKey"));
}
use of io.vertx.core.http.impl.headers.HeadersAdaptor in project vert.x by eclipse.
the class WebSocketHandshakeInboundHandler method handshakeComplete.
private Future<HeadersAdaptor> handshakeComplete(FullHttpResponse response) {
int sc = response.status().code();
if (sc != 101) {
String msg = "WebSocket upgrade failure: " + sc;
ByteBuf content = response.content();
if (content != null && content.readableBytes() > 0) {
msg += " (" + content.toString(StandardCharsets.UTF_8) + ")";
}
UpgradeRejectedException failure = new UpgradeRejectedException(msg, sc);
return Future.failedFuture(failure);
} else {
try {
handshaker.finishHandshake(chctx.channel(), response);
return Future.succeededFuture(new HeadersAdaptor(response.headers()));
} catch (WebSocketHandshakeException e) {
return Future.failedFuture(e);
}
}
}
use of io.vertx.core.http.impl.headers.HeadersAdaptor in project vert.x by eclipse.
the class HeadersTestBase method testSetAllOnExistingMapUsingHashMapHttp1.
@Test
public void testSetAllOnExistingMapUsingHashMapHttp1() {
MultiMap mainMap = new HeadersAdaptor(HeadersMultiMap.httpHeaders());
mainMap.add("originalKey", "originalValue");
Map<String, String> setAllMap = new HashMap<>();
setAllMap.put("originalKey", "newValue");
setAllMap.put("anotherKey", "anotherValue");
MultiMap result = mainMap.setAll(setAllMap);
assertNotNull(result);
assertFalse(result.isEmpty());
assertEquals(2, result.size());
assertEquals("newValue", result.get("originalKey"));
assertEquals("anotherValue", result.get("anotherKey"));
}
Aggregations