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

com.firefly.server.http2.ServerSecureEncoder Maven / Gradle / Ivy

There is a newer version: 5.0.0-dev6
Show newest version
package com.firefly.server.http2;

import com.firefly.codec.http2.stream.HTTPConnection;
import com.firefly.net.EncoderChain;
import com.firefly.net.Session;
import com.firefly.utils.concurrent.Callback;

import java.nio.ByteBuffer;

public class ServerSecureEncoder extends EncoderChain {

    @Override
    public void encode(Object message, Session session) throws Throwable {
        HTTPConnection connection = (HTTPConnection) session.getAttachment();

        switch (connection.getHttpVersion()) {
            case HTTP_2:
                HTTP2ServerConnection http2ServerConnection = (HTTP2ServerConnection) connection;
                http2ServerConnection.writeEncryptMessage(message);
                break;
            case HTTP_1_1:
                HTTP1ServerConnection http1ServerConnection = (HTTP1ServerConnection) connection;
                if (message instanceof ByteBuffer) {
                    http1ServerConnection.getSecureSession().write((ByteBuffer) message, Callback.NOOP);
                } else if (message instanceof ByteBuffer[]) {
                    http1ServerConnection.getSecureSession().write((ByteBuffer[]) message, Callback.NOOP);
                } else {
                    throw new IllegalArgumentException(
                            "the http1 encoder must receive the ByteBuffer, but this message type is "
                                    + message.getClass());
                }
                break;
            default:
                throw new IllegalStateException("server does not support the http version " + connection.getHttpVersion());
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy