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

org.littleshoot.proxy.extras.HAProxyMessageEncoder Maven / Gradle / Ivy

Go to download

LittleProxy is a high performance HTTP proxy written in Java and using the Netty networking framework.

The newest version!
package org.littleshoot.proxy.extras;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * Encodes an HAProxy proxy protocol header
 *
 * @see Proxy Protocol Specification
 */
public class HAProxyMessageEncoder extends MessageToByteEncoder {

    @Override
    protected void encode(ChannelHandlerContext ctx, ProxyProtocolMessage msg, ByteBuf out) {
        out.writeBytes(getHaProxyMessage(msg));
    }

    private byte [] getHaProxyMessage(ProxyProtocolMessage msg) {
        return String.format("%s %s %s %s %s %s\r\n", msg.getCommand(), msg.getProxiedProtocol(), msg.getSourceAddress(), msg.getDestinationAddress(), msg.getSourcePort(),
            msg.getDestinationPort()).getBytes();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy