Title: http.server doesn't process Status header from CGI scripts
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.3
Status: open Resolution:
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: facundobatista, fdrake, martin.panter, orsenthil, rosslagerwall, v+python
Priority: normal Keywords:

Created on 2010-11-21 07:50 by v+python, last changed 2015-10-01 22:38 by martin.panter.

Messages (3)
msg121881 - (view) Author: Glenn Linderman (v+python) * Date: 2010-11-21 07:50
While it is documented that http.server (and Python 2's CGIHTTPServer) do not process the status header, and limit the usefulness of CGI scripts as a result, that doesn't make it less of a bug, just a documented bug.  But I guess that it might have to be called a feature request; I'll not argue if someone switches this to feature request, but I consider it a bug.

See related issue 10482 for subprocess to provide better features for avoiding deadlock situations.  There seems to be no general way using subprocess to avoid possible deadlock situations.  However, since CGI doesn't really use stderr much, and only for logging, which the scripts can do themselves (the module even provides for such), and because CGIs generally slurp stdin before creating stdout, it is possible to tweak sidestep use of subprocess.communicate, drop the stdout PIPE, and sequence the code to process stdin and then stdout, and not generally deadlock (some CGI scripts that don't above the stdin before stdout rule, might deadlock if called with POST and large inputs, but those are few).

By doing this, one can then add code to handle Status: headers, and avoid buffering large files on output (and on input).  The tradeoff is losing the stderr log; when that is hooked up, some error cases can trigger deadlocks by writing to stderr -- hence the subprocess issue mentioned above.
msg123515 - (view) Author: Glenn Linderman (v+python) * Date: 2010-12-07 02:50
Just to mention, with the added code from issue 10482, I was able to get a 3-stream functionality working great in http.server and also backported it to 2.6 CGIHTTPServer... and to properly process the Status: header on stdout.

Works very well in 2.6; Issue 8077 prevents form processing from working in 3.2a4, but otherwise it is working there also, and the experience in 2.6 indicates that once issue 8077 is resolved, it should work in 3.2 also.
msg252071 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-10-01 22:38
Issue 13893 was closed as a duplicate of this issue. There are patches and modified code there that may be worth looking at though.
Date User Action Args
2015-10-01 22:38:58martin.pantersetsuperseder: Make CGIHTTPServer capable of redirects (and status other than 200) ->

messages: + msg252071
nosy: + martin.panter
2012-03-16 08:22:59orsenthilsetsuperseder: Make CGIHTTPServer capable of redirects (and status other than 200)
2012-03-16 08:21:52orsenthilsetassignee: orsenthil
2012-02-05 14:56:19rosslagerwallsetnosy: + rosslagerwall
2012-02-05 11:08:50eric.araujolinkissue13893 superseder
2012-02-04 07:25:04eric.araujosettitle: http.server - doesn't process Status: header from CGI scripts -> http.server doesn't process Status header from CGI scripts
versions: + Python 3.3, - Python 3.2
2010-12-07 02:50:22v+pythonsetmessages: + msg123515
2010-11-21 17:00:02pitrousetnosy: + fdrake, facundobatista, orsenthil

type: behavior -> enhancement
versions: - Python 2.6, Python 3.1, Python 2.7
2010-11-21 07:50:41v+pythoncreate