In article <[EMAIL PROTECTED]>, Irmen de Jong <[EMAIL PROTECTED]> wrote:
> Ron Garret wrote: > > Here's my code. It's a teeny weeny little HTTP server. (I'm not really > > trying to reinvent the wheel here. What I'm really doing is writing a > > dispatching proxy server, but this is the shortest way to illustrate the > > problem I'm having): > > > > from SocketServer import * > > from socket import * > > from select import select > > > > class myHandler(StreamRequestHandler): > > def handle(self): > > print '>>>>>>>>>>>' > > while 1: > > sl = select([self.rfile],[],[])[0] > > if sl: > > l = self.rfile.readline() > > if len(l)<3: break > > print l, > > pass > > pass > > print>>self.wfile, 'HTTP/1.0 200 OK' > > print>>self.wfile, 'Content-type: text/plain' > > print>>self.wfile > > print>>self.wfile, 'foo' > > self.rfile.close() > > self.wfile.close() > > print '<<<<<<<<<<<<' > > pass > > pass > > > You shouldn't use a select() of your own inside the handle method. > The socketserver takes care of that for you. I don't understand why socketserver calling select should matter. (And BTW, there are no calls to select in SocketServer.py. I'm using Python2.5.) > What you need to do is read the input from the socket until you've reached > the end-of-input marker. That marker is an empty line containing just "\r\n" > when dealing with HTTP GET requests. > > Any reason don't want to use the BasicHTTPServer that comes with Python? Yes, but it's a long story. What I'm really doing is writing a dispatching proxy. It reads the HTTP request and then redirects it to a number of different servers depending on the URL. The servers are all local and served off of unix sockets, not TCP sockets (which is why I can't just configure Apache to do this). The reason I'm running this weird configuration (in case you're wondering) is because this is a development machine and multiple copies of the same website run on it simultaneously. Each copy of the site runs a customized server to handle AJAX requests efficiently. > > Anyway, try the following instead: > That won't work for POST requests. rg -- http://mail.python.org/mailman/listinfo/python-list