Simple example of BaseHTTPServer use

David Lees DavidL at raqia.com
Thu Jun 14 20:18:17 EDT 2001


Doug,

A little light just went on and maybe I get it.  If I want to have a
'Content-length: 572' in the header, do I need to issue a
'send_header('Content-length: 572') ?

Assuming that is correct, then I am responsible for computing the
content length.  There is only one thing I still don't get.  When I send
stuff back to the client using wfile.write('foo')
when do things get sent?  As soon as I issue the command or do I need to
do a flush or close or something like that?

Thanks,

david lees


Doug Fort wrote:
> 
> David Lees wrote:
> 
> > I would like to use the BaseHTTPServer class to handle a PUT  and send
> > back some http.  I am sending the headers back correctly I think, but no
> > data appears to be going back.  I am probably using the wfile instance
> > variable incorrectly.  Here is sample code I am working on.
> >
> > def do_PUT(self):
> >         self.send_response(200,'<response></response>\n')
> >         self.send_header("Content-type", "text/html")
> >         self.wfile.write('junker goes\nout here\n')
> >         self.end_headers()
> >
> >
> >
> > Thanks in advance.
> >
> > David Lees
> >
> I believe you need to call end_headers() before attempting to send any
> data.  end_headers() writes a blank line which is followed by the data.  I
> recommend Frederik Lundh's book "Python Standard Library" from O'Reilly, it
> has good clear examples and list lists at US$29.95 unlike the bloated $50
> books that line the shelves.
> 
> --
> Doug Fort <dougfort at downright.com>
> Senior Meat Manager
> Downright Software LLC
> http://www.downright.com
> 
> ______________________________________________________________________
> Posted Via Uncensored-News.Com - Still Only $9.95 - http://www.uncensored-news.com
>    With Seven Servers In California And Texas - The Worlds Uncensored News Source
>



More information about the Python-list mailing list