use of org.mockserver.dashboard.DashboardWebSocketHandler in project mockserver by mock-server.
the class PortUnificationHandler method switchToHttp.
private void switchToHttp(ChannelHandlerContext ctx, ByteBuf msg) {
ChannelPipeline pipeline = ctx.pipeline();
addLastIfNotPresent(pipeline, new HttpServerCodec(configuration.maxInitialLineLength(), configuration.maxHeaderSize(), configuration.maxChunkSize()));
addLastIfNotPresent(pipeline, new HttpContentDecompressor());
addLastIfNotPresent(pipeline, httpContentLengthRemover);
addLastIfNotPresent(pipeline, new HttpObjectAggregator(Integer.MAX_VALUE));
if (configuration.tlsMutualAuthenticationRequired() && !isSslEnabledUpstream(ctx.channel())) {
HttpResponse httpResponse = response().withStatusCode(426).withHeader("Upgrade", "TLS/1.2, HTTP/1.1").withHeader("Connection", "Upgrade");
if (MockServerLogger.isEnabled(Level.INFO)) {
mockServerLogger.logEvent(new LogEntry().setLogLevel(Level.INFO).setMessageFormat("no tls for connection:{}returning response:{}").setArguments(ctx.channel().localAddress(), httpResponse));
}
ctx.channel().writeAndFlush(mockServerHttpResponseToFullHttpResponse.mapMockServerResponseToNettyResponse(// Upgrade Required
httpResponse).get(0)).addListener((ChannelFuture future) -> future.channel().disconnect().awaitUninterruptibly());
} else {
addLastIfNotPresent(pipeline, new CallbackWebSocketServerHandler(httpState));
addLastIfNotPresent(pipeline, new DashboardWebSocketHandler(httpState, isSslEnabledUpstream(ctx.channel()), false));
addLastIfNotPresent(pipeline, new MockServerHttpServerCodec(configuration, mockServerLogger, isSslEnabledUpstream(ctx.channel()), ctx.channel().localAddress(), SniHandler.retrieveClientCertificates(mockServerLogger, ctx)));
addLastIfNotPresent(pipeline, new HttpRequestHandler(configuration, server, httpState, actionHandler));
pipeline.remove(this);
ctx.channel().attr(LOCAL_HOST_HEADERS).set(getLocalAddresses(ctx));
// fire message back through pipeline
ctx.fireChannelRead(msg.readBytes(actualReadableBytes()));
}
}
Aggregations