*** medusa_http.py.orig Thu Aug 21 22:00:55 2003 --- medusa_http.py Fri Aug 22 18:00:14 2003 *************** *** 16,21 **** --- 16,33 ---- from quixote.publish import Publisher from quixote.errors import PublishError + + class iterator_producer: + def __init__(self, iterator): + self.iterator = iterator + + def more(self): + try: + return str(self.iterator.next()) + except StopIteration: + return '' + + class QuixoteHandler: def __init__ (self, publisher, server_name, server): """QuixoteHandler(publisher:Publisher, server_name:string, *************** *** 87,93 **** --- 99,112 ---- except: output = self.publisher.finish_failed_request(qreq) + producer = None if output: + if hasattr(output, "more"): # output is a producer + producer = output + output = '' + elif hasattr(output, "next"): # output is an iterator/generator + producer = iterator_producer(output) + output = '' qreq.response.set_body(str(output)) output_file = StringIO() *************** *** 99,104 **** --- 118,125 ---- # Copy headers from Quixote's HTTP response for hdr in msg.keys(): + if producer and hdr.lower() == "content-length": + continue # do not put "Content-Length: 0" in output values = msg.getheaders(hdr) # XXX Medusa's HTTP request is buggy, and only allows unique # headers. *************** *** 107,115 **** request.response(qreq.response.status_code) ! # XXX should we set a default Last-Modified time? ! request['Content-Length'] = '0' ! if output: request.push(output) request['Content-Length'] = str(len(output)) --- 128,136 ---- request.response(qreq.response.status_code) ! if producer: ! request.push(producer) ! elif output: request.push(output) request['Content-Length'] = str(len(output))