Fix traceback in x-forward-for in cases of localhost

This commit is contained in:
Griatch 2020-03-23 23:20:27 +01:00
parent ea802b4567
commit 6c1a77eecc

View file

@ -70,14 +70,15 @@ class HTTPChannelWithXForwardedFor(http.HTTPChannel):
Check to see if this is a reverse proxied connection. Check to see if this is a reverse proxied connection.
""" """
CLIENT = 0 if self.requests:
http.HTTPChannel.allHeadersReceived(self) CLIENT = 0
req = self.requests[-1] http.HTTPChannel.allHeadersReceived(self)
client_ip, port = self.transport.client req = self.requests[-1]
proxy_chain = req.getHeader("X-FORWARDED-FOR") client_ip, port = self.transport.client
if proxy_chain and client_ip in _UPSTREAM_IPS: proxy_chain = req.getHeader("X-FORWARDED-FOR")
forwarded = proxy_chain.split(", ", 1)[CLIENT] if proxy_chain and client_ip in _UPSTREAM_IPS:
self.transport.client = (forwarded, port) forwarded = proxy_chain.split(", ", 1)[CLIENT]
self.transport.client = (forwarded, port)
# Monkey-patch Twisted to handle X-Forwarded-For. # Monkey-patch Twisted to handle X-Forwarded-For.