
org.testifyproject.github.dockerjava.netty.handler.HttpConnectionHijackHandler Maven / Gradle / Ivy
package org.testifyproject.testifyproject.github.dockerjava.netty.handler;
import org.testifyproject.testifyproject.netty.channel.ChannelHandlerContext;
import org.testifyproject.testifyproject.netty.handler.codec.http.FullHttpResponse;
import org.testifyproject.testifyproject.netty.handler.codec.http.HttpClientUpgradeHandler;
import org.testifyproject.testifyproject.netty.handler.codec.http.HttpRequest;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.CountDownLatch;
public class HttpConnectionHijackHandler implements HttpClientUpgradeHandler.UpgradeCodec {
private CountDownLatch latch = new CountDownLatch(1);
private HttpResponseHandler httpResponseHandler;
public HttpConnectionHijackHandler(HttpResponseHandler httpResponseHandler) {
this.httpResponseHandler = httpResponseHandler;
}
@Override
public void upgradeTo(ChannelHandlerContext ctx, FullHttpResponse upgradeResponse) throws Exception {
httpResponseHandler.channelRead(ctx, upgradeResponse);
ctx.pipeline().addLast(httpResponseHandler);
latch.countDown();
}
@Override
public Collection setUpgradeHeaders(ChannelHandlerContext ctx, HttpRequest upgradeRequest) {
return Collections.emptyList();
}
@Override
public CharSequence protocol() {
return "tcp";
}
public void awaitUpgrade() {
try {
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy