1

我正在编写一个原型 CGI 应用程序以在 IIS 7.0 服务器上运行,这最终将导致该应用程序发送许多 http 分块响应,这些响应是为响应可能需要一些时间来生成实际数据的查询而生成的。

在深入研究这方面(即生成真实数据)之前,我想测试我的 cgi 应用程序是否实际上在非解析头模式下运行(即 cgi 应用程序本身生成所有头文件,而 IIS 只是将所有输出返回到请求 http 浏览器/代理。

所以我写了一个简单的应用程序,它返回以下内容(注意时间戳 - 每个带时间戳的行之间有 1 秒的暂停,正如文本所暗示的那样,这需要 10 多秒才能执行 - 你实际上可以在命令行并观察这个时间。

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

当我在服务器上安装 exe 并在 Internet Explorer 中打开它时,会显示预期的文本(时间不同,因为我在一天中的不同时间和不同时区运行它们):

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

但是 - 在整个 10 秒过去之前,什么都不会显示。(注意 - 铬的结果相同)

为了确保这一点,我在文本编辑器中制作了一个 http 请求,并将其粘贴到服务器的 80 端口上的 telnet 中,并在整个响应之前观察到 10 秒的间隙,如上所示。

我得到相同的结果,无论 exe 是否具有前缀“nph-” - 我在 telnet 中执行了相同的测试,使用“nph-hello.exe”、“nphhello.exe”和“hello.exe”,使用以下内容:

(注:识别地址已针对本帖进行了调整)

GET /cgi-bin/nph-hello.exe HTTP/1.0
Host: www.myserver.com:80
From: someone@gmail.com
User-Agent: telnet/1.0

(有关 exe 命名前缀的相关性,请阅读http://support.microsoft.com/default.aspx?scid=kb;EN-US;q176113下的“解决方案”下的注释,以“作为解决方法...”开头)

我似乎没有在 telnet 中观察到与 exe 名称前缀相关的任何可辨别的输出差异,这使我相信此信息要么已过时,要么需要启用其他东西才能打开此功能,这显然需要发生在 cgi 应用程序启动之前 - 这解释了为什么使用前缀而不是应用程序本身所做的事情 - 即 IIS 需要知道是否等待响应)

虽然从表面上看,它正在实现预期的结果 - 数据找到了请求 http 代理的方式 - 我希望它实时发生,因此可以在发出请求时显示进度更新。

所以我的问题:

1)是否需要进行一些设置才能打开 NPH(或者前缀是否正确?)

2)cgi 应用程序是否可以进行一些测试来判断它是否真的处于 NPH 模式?

3) 是否打算将标准输出(即响应数据)实时传送到请求代理,或者 IIS 是否必须首先以某种方式缓冲和解析它?

4

0 回答 0