Are the built-in HTTP servers production quality?

Grant Edwards grante at visi.com
Mon Jul 19 14:28:49 EDT 2004


On 2004-07-19, Irmen de Jong <irmen at -nospam-remove-this-xs4all.nl> wrote:

> Rather than treating text files (with content-type text/...) as any
> other -binary- file, I now think that it's actually better to read them
> in and convert the line endings to CR LF. But this requires:
>
> - buffering of the entire text file in memory during the CR LF conversion

Why do you have to buffer the entire file?  You couldm ake two
almost-identical conversion passes through the file: the first
time, just count the "output" bytes.  Finish sending the HTTP
headers out, then make the second pass actually writing the
output bytes.  

If the OS had enough spare RAM sitting around, it will buffer
the file for you and the second pass won't even hit the disk.

> - fixing the content-type at the end because it's not the same as
>   the filesize (this was the original problem I solved).

-- 
Grant Edwards                   grante             Yow!  Here I am at the flea
                                  at               market but nobody is buying
                               visi.com            my urine sample bottles...



More information about the Python-list mailing list