[Twisted-Python] Custom webserver

Vijay Rao vijay at accellion.com
Wed Jun 18 23:57:55 MDT 2003


At 06:34 16/06/2003 -0500, you wrote:

>Message: 9
>Date: Mon, 16 Jun 2003 10:03:52 +0300
>From: Tommi Virtanen <tv at twistedmatrix.com>
>To: twisted-python at twistedmatrix.com
>Subject: Re: [Twisted-Python] Custom webserver
>Reply-To: twisted-python at twistedmatrix.com
>
>On Mon, Jun 16, 2003 at 09:57:13AM +0530, Vijay Rao wrote:
> > I am trying to use twisted as a webserver that serves files only for
> > requests from the localhost ie the desktop on which it is running by
> > mapping localhost(127.0.0.1) to a domain pattern ( thru the hosts file on
> > windows ) so that a particular type of URL is served from this webserver.
>
>         Easiest way is to make it bind to 127.0.0.1. There's currently
>         no support in mktap web for this, though there really should
>         be.
>
>--
>:(){ :|:&};:

Thanks , any pointer as to how to achieve this binding.
Also for refusing any external request I tried this hack and it works :

(from protocols/http.py)

     def lineReceived(self, line):
         if self.__first_line:
             # if this connection is not persistent, drop any data which
             # the client (illegally) sent after the last request.
......
.....
......
             if len(parts) != 3:
                 self.transport.write("HTTP/1.1 400 Bad Request\r\n\r\n")
                 self.transport.loseConnection()
                 return
             client = self.transport.getPeer()
             host = self.transport.getHost()
             if client[1] != '127.0.0.1' or host[1] != '127.0.0.1' :
                 self.transport.write("HTTP/1.1 404 Forbidden\r\n\r\n")
                 self.transport.loseConnection()
                 return
.......
....

Can this cause any other problem ( One thing I can see is that new channels 
are created for each external request refused in this manner )
And the requesting client browser is also not being able to display the 
result sent.

Regards,
Vijay





More information about the Twisted-Python mailing list