All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dockerjava.netty.handler.HttpConnectionHijackHandler Maven / Gradle / Ivy

There is a newer version: 3.4.0
Show newest version
package com.github.dockerjava.netty.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpClientUpgradeHandler;
import io.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 - 2024 Weber Informatics LLC | Privacy Policy