mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-24 21:09:44 +00:00
avoid about-to-be-deprecated getClientIP if we can
Use the replacement, getClientAddress. But have a fallback to getClientIP to keep supporting older versions of Twisted.
This commit is contained in:
parent
edf3c7aac7
commit
8eb83bbfb9
@ -2,6 +2,10 @@ import re, time
|
|||||||
from twisted.application import service, strports, internet
|
from twisted.application import service, strports, internet
|
||||||
from twisted.web import http, static
|
from twisted.web import http, static
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
from twisted.internet.address import (
|
||||||
|
IPv4Address,
|
||||||
|
IPv6Address,
|
||||||
|
)
|
||||||
from nevow import appserver, inevow
|
from nevow import appserver, inevow
|
||||||
from allmydata.util import log, fileutil
|
from allmydata.util import log, fileutil
|
||||||
|
|
||||||
@ -119,7 +123,7 @@ class MyRequest(appserver.NevowRequest):
|
|||||||
"web: %(clientip)s %(method)s %(uri)s %(code)s "
|
"web: %(clientip)s %(method)s %(uri)s %(code)s "
|
||||||
"%(length)s%(error)s"
|
"%(length)s%(error)s"
|
||||||
),
|
),
|
||||||
clientip=self.getClientIP(),
|
clientip=_get_client_ip(self),
|
||||||
method=self.method,
|
method=self.method,
|
||||||
uri=uri,
|
uri=uri,
|
||||||
code=self.code,
|
code=self.code,
|
||||||
@ -130,6 +134,18 @@ class MyRequest(appserver.NevowRequest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_client_ip(request):
|
||||||
|
try:
|
||||||
|
get = request.getClientAddress
|
||||||
|
except AttributeError:
|
||||||
|
return request.getClientIP()
|
||||||
|
else:
|
||||||
|
client_addr = get()
|
||||||
|
if isinstance(client_addr, (IPv4Address, IPv6Address)):
|
||||||
|
return client_addr.host
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class WebishServer(service.MultiService):
|
class WebishServer(service.MultiService):
|
||||||
name = "webish"
|
name = "webish"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user