[Twisted-Python] Re: [Twisted-commits] CVS: Twisted/twisted/web server.py,1.20,1.21

Kevin Turner acapnotic at twistedmatrix.com
Wed Oct 17 13:43:35 EDT 2001


On Wed, Oct 17, 2001 at 05:35:59AM -0500, Benjamin Bruheim wrote:
> Committing this under doubt: fixes traceback when windows is off-line, 
> and in theory it should get servers behind NAT return the correct hostname.
> Should only affect SERVER_NAME in CGIs.
> 
> diff -b -u -d -r1.20 -r1.21
> --- server.py	2001/10/16 20:09:10	1.20
> +++ server.py	2001/10/17 10:35:57	1.21
> @@ -174,8 +174,6 @@
>      def __repr__(self):
>          return '<%s %s %s>'% (self.method, self.uri, self.clientproto)
>  
> -    _host = socket.gethostbyaddr(socket.gethostname())[0]
> -
>      def process(self):
>          "Process a request."
> @@ -395,7 +393,7 @@
>      def getHost(self):
> -        return self._host
> +        return socket.gethostbyaddr(self.transport.getHost()[1])

The before-and-after code returns two different types:
before it returned just the 'hostname' element [0] of
the gethostbyaddr tuple, and now it returns the whole
thing.

Also, it's not evident to me from the documentation that
transport.getHost always returns an IP address, which I
think gethostbyaddr needs.

Would it be possible to do something along the lines of::

class Request:
    _host = None

    def getHost(self):
        if not self._host:
            Request._host = getHostSomehowOrOther
        return self._host

as doing gethostbyaddr for every Request instance sounds potentially
problematic to me.  (Especially since that's not using the non-blocking
asynchronous resolver.)

But if you have a dynamic IP and so you suspect your full hostname of
changing on you...  hmm.  Is there a way to be notified when the network
connection comes up (there must be, the silly MSN guys start blinking
right away), and this could trigger some sort of "Reinitialize" call in
the Twisted server?

-- 
Kevin Turner <acapnotic at twistedmatrix.com> | OpenPGP encryption welcome here
The moon is waxing crescent, 0.6% illuminated, 0.7 days old.





More information about the Twisted-Python mailing list