I am writing a prototype CGI application to run on an IIS 7.0 server, which will ultimately result in that application sending a number of http chunked responses that are generated in response to a query that may take some time to generate the actual data.
before delving into that side of things (ie generating the real data), i wanted to test if my cgi app is in fact running in non parsed header mode (ie the cgi app itself generates all headers, and IIS just returns all output to the requesting http browser/agent.
so i wrote a simple app that returns the following (note timetamps - there is a 1 second pause between each timestamped line, and as the text implies, this take just over 10 seconds to execute - you can in fact run the cgi app on the command line and observe this timing.
HTTP/1.1 200 OK
Date: Sun, 17 Jul 2011 09:07:47 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
17;
NPH CGI Chunked Example
4D;
the fat cat sat on the mat, perplexed at the antics of the quick brown fox.
2D;
counting ... 1... the time is now 09:07:48
2D;
counting ... 2... the time is now 09:07:49
2D;
counting ... 3... the time is now 09:07:50
2D;
counting ... 4... the time is now 09:07:50
2D;
counting ... 5... the time is now 09:07:51
2D;
counting ... 6... the time is now 09:07:52
2D;
counting ... 7... the time is now 09:07:53
2D;
counting ... 8... the time is now 09:07:54
2D;
counting ... 9... the time is now 09:07:55
2E;
counting ... 10... the time is now 09:07:56
18;
NPH Chunked Example Ends
0
When I install the exe on the server and open it in internet explorer, the expected text is displayed (times differ as i ran them at a different time of day, and in different time zones):
NPH CGI Chunked Example
the fat cat sat on the mat, perplexed at the antics of the quick brown fox.
counting ... 1... the time is now 16:14:58
counting ... 2... the time is now 16:14:59
counting ... 3... the time is now 16:15:00
counting ... 4... the time is now 16:15:01
counting ... 5... the time is now 16:15:02
counting ... 6... the time is now 16:15:03
counting ... 7... the time is now 16:15:04
counting ... 8... the time is now 16:15:05
counting ... 9... the time is now 16:15:06
counting ... 10... the time is now 16:15:07
NPH Chunked Example Ends
HOWEVER - nothing is displayed until after the entire 10 seconds has elapsed. (note - same result in chrome)
to make sure, i crafted a http request in a text editor and pasted it into telnet on port 80 to the server, and observed a 10 second gap before the entire response as shown above.
I get the same result, regardless of wether the exe has the prefix "nph-" or not - i performed the same test in telnet, with "nph-hello.exe", "nphhello.exe" and "hello.exe", using the following:
(note:identifying addresses are adjusted for this post)
GET /cgi-bin/nph-hello.exe HTTP/1.0
Host: www.myserver.com:80
From: someone@gmail.com
User-Agent: telnet/1.0
(for relevance of exe naming prefix, read the notes at http://support.microsoft.com/default.aspx?scid=kb;EN-US;q176113 under "Resolution" beginning "as a workaround...")
I do not appear to observe any discernible output difference in telnet relating to the exe name prefix which leads me to believe this information is either out of date, or that something else needs to be enabled to turn on this feature, which clearly needs to happen before the cgi app is started - which explains why the prefix is used as opposed to something the app itself does - ie IIS needs to know wether to wait for a response)
whilst on the surface, it is achieving the desired result - the data finds it's way to the requesting http agent - i would prefer it to happen in real time, so progress updates can be displayed as the request is made.
so my questions:
1) is there some setting that needs to be made to turn on NPH (or is the prefix correct?)
2) is there some test the cgi app can make to tell if it is really in NPH mode?
3) is it intended that stddout (ie response data) be piped to the requesting agent in real time, or does IIS absolutely have to buffer and parse it in some way first?