<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><blockquote type="cite" class="">On Aug 31, 2015, at 11:48 PM, Zuhaib Siddique <<a href="mailto:zuhaib@hipchat.com" class="">zuhaib@hipchat.com</a>> wrote:<br class=""><br class="">Hey all,<br class=""></blockquote><div class=""><span class=""><br class=""></span></div><div class=""><span class="">Hi Zuhaib!  Thanks for writing.</span></div><br class=""><blockquote type="cite" class="">I am looking at using HAProxy in front of Twisted for TCP connection and need to pass the source IP along.  We are currently looking at hacking tcp.py to add support for this: <a href="http://www.haproxy.org/download/1.5/doc/proxy-" class="">http://www.haproxy.org/download/1.5/doc/proxy-</a>protocol.txt but wondering if this is something someone is already working on for twisted or maybe I dont need to hack tcp.py.<br class=""></blockquote><div class=""><span class=""><br class=""></span></div><div class="">I am not aware of an implementation of this protocol, but it looks very interesting!  The usual argument I hear for load-balancing HTTP rather than TCP is that you lose information about the network protocol you're speaking that would be preserved by the "Forwarded" or "X-Forwarded-For" header.  But if Twisted supported this protocol then it could live behind haproxy with no loss of information, regardless of protocol!  And if it had a server-side version of this it could load-balance other similarly equipped software.  Exciting possibilities all around.</div><div class=""><br class=""></div><div class="">Hacking tcp.py is definitely the <i class="">wrong</i> way to go about implementing it, though.</div><div class=""><br class=""></div><div class="">The <i class="">right</i> way to go about this would be to implement a transceiver: something that implements a protocol for its transport, and implements a transport for another protocol.  The best example of this within Twisted right now is twisted.protocols.tls, the OpenSSL integration that superseded our much grosser, less flexible hacking of tcp.py.</div><div class=""><br class=""></div><div class="">So for this proxy protocol, you'd have a protocol that waited until it received the full PROXY protocol header (whether text-based or binary) and implement ITCPTransport to have values in getHost() and getPeer() that correspond to the values received from the PROXY message.</div><div class=""><br class=""></div><div class="">Does that make sense?</div><div class=""><br class=""></div><div class="">If I have an idle moment I might try my hand at an implementation myself, but I am not always super reliable ;-).</div><br class=""><blockquote type="cite" class="">Thanks<br class="">Zuhaib<br class=""></blockquote><div class=""><br class=""></div><div class="">-glyph</div><div><br class=""></div></body></html>