<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 13, 2017, at 11:01 PM, Ilya Skriblovsky <<a href="mailto:ilyaskriblovsky@gmail.com" class="">ilyaskriblovsky@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">Hi,</div><div class=""><br class=""></div><div class="">I'm using Twisted Web server behind Nginx reverse-proxy and I'm getting backend's internal host:port from Request.getHost().</div><div class=""><br class=""></div><div class="">Seems like Request.host is explicitly set to socket's address (i.e. internal address) here: ​<a href="https://github.com/twisted/twisted/blob/trunk/src/twisted/web/http.py#L838" class="">https://github.com/twisted/twisted/blob/trunk/src/twisted/web/http.py#L838</a> But comment at ​<a href="https://github.com/twisted/twisted/blob/trunk/src/twisted/web/http.py#L1297" class="">https://github.com/twisted/twisted/blob/trunk/src/twisted/web/http.py#L1297</a> and what this method does points that Request.host meant to reflect Host header of the request, i.e. user-visible hostname and port.</div><div class=""><br class=""></div><div class="">This creates problems for me when using Klein because it correctly uses Request.getHost() to create host part of URLs for redirects.</div><div class=""><br class=""></div><div class="">It seems like inconsistency in Twisted code. I'd expect Request.host should be only set from the Host request header to reflect user-visible hostname, not the internal backend server's address. Or may be I'm missing something?</div></div></div></blockquote></div><div><br class=""></div><div>You're absolutely correct!  I even filed a ticket for this functionality, 5 years ago: <a href="https://twistedmatrix.com/trac/ticket/5807" class="">https://twistedmatrix.com/trac/ticket/5807</a>  There's even a branch for it.  Oddly enough we <i class="">do</i> have a <i class="">private</i> _XForwardedForRequest, but... it's only used for logging, for some reason.</div><div><br class=""></div><div><div><div>If you want accurate access logging and request information, <a href="https://twistedmatrix.com/trac/ticket/7704" class="">https://twistedmatrix.com/trac/ticket/7704</a> will probably also be of interest to you.</div><div class=""><br class=""></div></div></div><div><div>I'm so sorry you've hit this glaring deficiency in Twisted.</div><div><div><br class=""></div></div><div>On the other hand: I'm so glad that you've hit this glaring deficiency in Twisted!  I hope you will be motivated to fix it :-).  It's bothered me for quite some time that we don't play nicely with proxying setups, when such setups are so <i class="">incredibly</i> common.  If you can write pull requests to fix these issues and put them into review, I'm pretty sure you will find an enthusiastic reviewer quickly.</div></div><div><br class=""></div><div>-glyph</div></body></html>