org.littleshoot.proxy.extras.HAProxyMessageEncoder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of littleproxy Show documentation
Show all versions of littleproxy Show documentation
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();
}
}