Simple Webserver problem

Irmen de Jong irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Thu Oct 30 19:31:21 EST 2003


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).

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.

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