Re: internal vs. external hostname in Request.getHost9)
Ilya Skriblovsky <[email protected]> Tue, 14 Mar 2017 07:33:41 +0000
| Newsgroups | gmane.comp.python.twisted.web |
|---|---|
| Message-ID | <CAOG7vkzaKFM=G13F_Gd2VJ34VybSC+iw8_APWWm0hwCtDTgf4A@mail.gmail.com> |
--===============2986571557227979277== Content-Type: multipart/alternative; boundary=001a1134fed282921f054aabd920 --001a1134fed282921f054aabd920 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Thanks, I will study tickets you mentioned and hopefully fix it. Quick-n-dirty fix gave me only two failed tests and in both cases it seems to be a wrong assumption in tests. So I hope this change won't break the world. -- ilya =D0=B2=D1=82, 14 =D0=BC=D0=B0=D1=80. 2017 =D0=B3. =D0=B2 10:12, Glyph Lefko= witz <[email protected]>: > > On Mar 13, 2017, at 11:01 PM, Ilya Skriblovsky <[email protected]= > > wrote: > > Hi, > > I'm using Twisted Web server behind Nginx reverse-proxy and I'm getting > backend's internal host:port from Request.getHost(). > > Seems like Request.host is explicitly set to socket's address (i.e. > internal address) here: =E2=80=8B > https://github.com/twisted/twisted/blob/trunk/src/twisted/web/http.py#L83= 8 > But comment at =E2=80=8B > https://github.com/twisted/twisted/blob/trunk/src/twisted/web/http.py#L12= 97 > and what this method does points that Request.host meant to reflect Host > header of the request, i.e. user-visible hostname and port. > > This creates problems for me when using Klein because it correctly uses > Request.getHost() to create host part of URLs for redirects. > > 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 missin= g > something? > > > You're absolutely correct! I even filed a ticket for this functionality, > 5 years ago: https://twistedmatrix.com/trac/ticket/5807 There's even a > branch for it. Oddly enough we *do* have a *private* > _XForwardedForRequest, but... it's only used for logging, for some reason= . > > If you want accurate access logging and request information, > https://twistedmatrix.com/trac/ticket/7704 will probably also be of > interest to you. > > I'm so sorry you've hit this glaring deficiency in Twisted. > > 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 f= or > quite some time that we don't play nicely with proxying setups, when such > setups are so *incredibly* 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. > > -glyph > _______________________________________________ > Twisted-web mailing list > [email protected] > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web > --001a1134fed282921f054aabd920 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Thanks, I will study tickets you mentioned and hopefully f= ix it.<div>Quick-n-dirty fix gave me only two failed tests and in both case= s it seems to be a wrong assumption in tests. So I hope this change won'= ;t break the world.</div><div><br></div><div>-- ilya<br><br><div class=3D"g= mail_quote"><div dir=3D"ltr">=D0=B2=D1=82, 14 =D0=BC=D0=B0=D1=80. 2017 =D0= =B3. =D0=B2 10:12, Glyph Lefkowitz <<a href=3D"mailto:glyph@twistedmatri= x.com">[email protected]</a>>:<br></div><blockquote class=3D"gmail= _quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:= 1ex"><div style=3D"word-wrap:break-word" class=3D"gmail_msg"><br class=3D"g= mail_msg"><div class=3D"gmail_msg"><blockquote type=3D"cite" class=3D"gmail= _msg"><div class=3D"gmail_msg">On Mar 13, 2017, at 11:01 PM, Ilya Skriblovs= ky <<a href=3D"mailto:[email protected]" class=3D"gmail_msg" tar= get=3D"_blank">[email protected]</a>> wrote:</div><br class=3D"m= _-3306553942595082654Apple-interchange-newline gmail_msg"><div class=3D"gma= il_msg"><div dir=3D"ltr" class=3D"gmail_msg"><div class=3D"gmail_msg">Hi,</= div><div class=3D"gmail_msg"><br class=3D"gmail_msg"></div><div class=3D"gm= ail_msg">I'm using Twisted Web server behind Nginx reverse-proxy and I&= #39;m getting backend's internal host:port from Request.getHost().</div= ><div class=3D"gmail_msg"><br class=3D"gmail_msg"></div><div class=3D"gmail= _msg">Seems like Request.host is explicitly set to socket's address (i.= e. internal address) here: =E2=80=8B<a href=3D"https://github.com/twisted/t= wisted/blob/trunk/src/twisted/web/http.py#L838" class=3D"gmail_msg" target= =3D"_blank">https://github.com/twisted/twisted/blob/trunk/src/twisted/web/h= ttp.py#L838</a> But comment at =E2=80=8B<a href=3D"https://github.com/twist= ed/twisted/blob/trunk/src/twisted/web/http.py#L1297" class=3D"gmail_msg" ta= rget=3D"_blank">https://github.com/twisted/twisted/blob/trunk/src/twisted/w= eb/http.py#L1297</a> and what this method does points that Request.host mea= nt to reflect Host header of the request, i.e. user-visible hostname and po= rt.</div><div class=3D"gmail_msg"><br class=3D"gmail_msg"></div><div class= =3D"gmail_msg">This creates problems for me when using Klein because it cor= rectly uses Request.getHost() to create host part of URLs for redirects.</d= iv><div class=3D"gmail_msg"><br class=3D"gmail_msg"></div><div class=3D"gma= il_msg">It seems like inconsistency in Twisted code. I'd expect Request= .host should be only set from the Host request header to reflect user-visib= le hostname, not the internal backend server's address. Or may be I'= ;m missing something?</div></div></div></blockquote></div><div class=3D"gma= il_msg"><br class=3D"gmail_msg"></div></div><div style=3D"word-wrap:break-w= ord" class=3D"gmail_msg"><div class=3D"gmail_msg">You're absolutely cor= rect!=C2=A0 I even filed a ticket for this functionality, 5 years ago:=C2= =A0<a href=3D"https://twistedmatrix.com/trac/ticket/5807" class=3D"gmail_ms= g" target=3D"_blank">https://twistedmatrix.com/trac/ticket/5807</a> =C2=A0T= here's even a branch for it.=C2=A0 Oddly enough we <i class=3D"gmail_ms= g">do</i> have a <i class=3D"gmail_msg">private</i> _XForwardedForRequest, = but... it's only used for logging, for some reason.</div><div class=3D"= gmail_msg"><br class=3D"gmail_msg"></div><div class=3D"gmail_msg"><div clas= s=3D"gmail_msg"><div class=3D"gmail_msg">If you want accurate access loggin= g and request information,=C2=A0<a href=3D"https://twistedmatrix.com/trac/t= icket/7704" class=3D"gmail_msg" target=3D"_blank">https://twistedmatrix.com= /trac/ticket/7704</a> will probably also be of interest to you.</div><div c= lass=3D"gmail_msg"><br class=3D"gmail_msg"></div></div></div><div class=3D"= gmail_msg"><div class=3D"gmail_msg">I'm so sorry you've hit this gl= aring deficiency in Twisted.</div><div class=3D"gmail_msg"><div class=3D"gm= ail_msg"><br class=3D"gmail_msg"></div></div><div class=3D"gmail_msg">On th= e other hand: I'm so glad that you've hit this glaring deficiency i= n Twisted!=C2=A0 I hope you will be motivated to fix it :-).=C2=A0 It's= bothered me for quite some time that we don't play nicely with proxyin= g setups, when such setups are so <i class=3D"gmail_msg">incredibly</i>=C2= =A0common.=C2=A0 If you can write pull requests to fix these issues and put= them into review, I'm pretty sure you will find an enthusiastic review= er quickly.</div></div><div class=3D"gmail_msg"><br class=3D"gmail_msg"></d= iv><div class=3D"gmail_msg">-glyph</div></div>_____________________________= __________________<br class=3D"gmail_msg"> Twisted-web mailing list<br class=3D"gmail_msg"> <a href=3D"mailto:[email protected]" class=3D"gmail_msg" target= =3D"_blank">[email protected]</a><br class=3D"gmail_msg"> <a href=3D"http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web" r= el=3D"noreferrer" class=3D"gmail_msg" target=3D"_blank">http://twistedmatri= x.com/cgi-bin/mailman/listinfo/twisted-web</a><br class=3D"gmail_msg"> </blockquote></div></div></div> --001a1134fed282921f054aabd920-- --===============2986571557227979277== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Twisted-web mailing list [email protected] http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web --===============2986571557227979277==--