Simple Webserver problem

Colin Brown cbrown at metservice.com
Thu Oct 30 19:57:40 EST 2003


"Irmen de Jong" <irmen at -NOSPAM-REMOVETHIS-xs4all.nl> wrote in message
news:3fa1ad58$0$58710$e4fe514c at news.xs4all.nl...
> Colin Brown wrote:
>
> > I am attempting to construct a simple webserver for browsing
> > text files with arbitrary file extensions based on the standard
> > Python library modules. Not all files are being returned as text.
> > [Python 2.3.2, Platform: Win2K, Browser IE6]. Code as below.
> >
> > Any assistance appreciated.
>                                            ^^^ that's your guy
>
> IE is known to act "smart" on downloaded files, and often
> ignores the content type that the web server supplies.
> If you try a better browser such as Firebird you'll see that
> it works (I tried, every file is served as text/plain).

Thanks. Why am I not surprised!

> There is one issue though.
> On windows there's a bug in SimpleHTTPServer:
> if files are served as text/* , it opens the file with
> mode 'r' instead of 'rb'. This breaks the content-length
> that is reported in the headers, because reading a file
> with mode 'r' may yield a string of different length than
> the file on disk (on windows).
> And the filesize on disk is what's reported.

I noted that in the code. Yes, my files would all have
been "text".

> Strictly speaking this should be fixed, but for your
> purpose it seems to work just fine as it is.
>
> --Irmen de Jong
>






More information about the Python-list mailing list