internal vs. external hostname in Request.getHost9)

Ilya Skriblovsky <[email protected]> Tue, 14 Mar 2017 06:01:00 +0000
Newsgroups gmane.comp.python.twisted.web
Message-ID <CAOG7vkxQWwrctx0d5_L2A5SAh_2e7mFA+j=PPGHQ9FAeoT0SUQ@mail.gmail.com>
--===============4429944543554445036==
Content-Type: multipart/alternative; boundary=94eb2c0b836008df99054aaa8e86

--94eb2c0b836008df99054aaa8e86
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

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#L838
But comment at =E2=80=8B
https://github.com/twisted/twisted/blob/trunk/src/twisted/web/http.py#L1297
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 missing something?

Thanks for reply

--
  ilya

--94eb2c0b836008df99054aaa8e86
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hi,</div><div><br></div><div>I&#39;m using Twisted We=
b server behind Nginx reverse-proxy and I&#39;m getting backend&#39;s inter=
nal host:port from Request.getHost().</div><div><br></div><div>Seems like R=
equest.host is explicitly set to socket&#39;s address (i.e. internal addres=
s) here: =E2=80=8B<a href=3D"https://github.com/twisted/twisted/blob/trunk/=
src/twisted/web/http.py#L838">https://github.com/twisted/twisted/blob/trunk=
/src/twisted/web/http.py#L838</a> But comment at =E2=80=8B<a href=3D"https:=
//github.com/twisted/twisted/blob/trunk/src/twisted/web/http.py#L1297">http=
s://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 h=
eader of the request, i.e. user-visible hostname and port.</div><div><br></=
div><div>This creates problems for me when using Klein because it correctly=
 uses Request.getHost() to create host part of URLs for redirects.</div><di=
v><br></div><div>It seems like inconsistency in Twisted code. I&#39;d expec=
t Request.host should be only set from the Host request header to reflect u=
ser-visible hostname, not the internal backend server&#39;s address. Or may=
 be I&#39;m missing something?</div><div><br></div><div>Thanks for reply</d=
iv><div><br></div><div>--</div><div>=C2=A0 ilya</div></div>

--94eb2c0b836008df99054aaa8e86--


--===============4429944543554445036==
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

--===============4429944543554445036==--