IHttpResponse::D isableBuffering 方法
禁用当前请求的响应缓冲。
语法
virtual VOID DisableBuffering(
VOID
) = 0;
参数
此方法不采用参数。
返回值
VOID
.
注解
IIS 7 包含默认启用的响应缓冲功能,但你可以使用 方法将其禁用 DisableBuffering
。 启用缓冲后,IIS 在向 Web 客户端返回任何数据之前,在内存中生成整个响应。 这会增加网络性能,但在某些情况下,你可能想要禁用缓冲。 例如,如果正在编写需要较长时间才能完成的应用程序,则 Web 客户端将不得不等待,直到 IIS 完全生成并返回响应,然后客户端才能看到任何数据。 禁用缓冲后,Web 客户端将以增量方式查看 IIS 返回的数据。
注意
方法 DisableBuffering
不禁用 CHttpModule::OnSendResponse 方法的缓冲。
示例
下面的代码示例演示如何使用 DisableBuffering
方法创建一个 HTTP 模块,该模块禁用当前请求的响应缓冲。
#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <httpserv.h>
// Create the module class.
class MyHttpModule : public CHttpModule
{
public:
REQUEST_NOTIFICATION_STATUS
OnBeginRequest(
IN IHttpContext * pHttpContext,
IN IHttpEventProvider * pProvider
)
{
UNREFERENCED_PARAMETER( pProvider );
// Retrieve a pointer to the response.
IHttpResponse * pHttpResponse =
pHttpContext->GetResponse();
// Test for an error.
if (pHttpResponse != NULL)
{
// Disable buffering for this response.
pHttpResponse->DisableBuffering();
}
// Return processing to the pipeline.
return RQ_NOTIFICATION_CONTINUE;
}
};
// Create the module's class factory.
class MyHttpModuleFactory : public IHttpModuleFactory
{
public:
HRESULT
GetHttpModule(
OUT CHttpModule ** ppModule,
IN IModuleAllocator * pAllocator
)
{
UNREFERENCED_PARAMETER( pAllocator );
// Create a new instance.
MyHttpModule * pModule = new MyHttpModule;
// Test for an error.
if (!pModule)
{
// Return an error if the factory cannot create the instance.
return HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY );
}
else
{
// Return a pointer to the module.
*ppModule = pModule;
pModule = NULL;
// Return a success status.
return S_OK;
}
}
void Terminate()
{
// Remove the class from memory.
delete this;
}
};
// Create the module's exported registration function.
HRESULT
__stdcall
RegisterModule(
DWORD dwServerVersion,
IHttpModuleRegistrationInfo * pModuleInfo,
IHttpServer * pGlobalInfo
)
{
UNREFERENCED_PARAMETER( dwServerVersion );
UNREFERENCED_PARAMETER( pGlobalInfo );
return pModuleInfo->SetRequestNotifications(
new MyHttpModuleFactory,
RQ_BEGIN_REQUEST,
0
);
}
模块必须导出 RegisterModule 函数。 可以通过为项目创建模块定义 (.def) 文件导出此函数,也可以使用 开关编译模块 /EXPORT:RegisterModule
。 有关详细信息,请参阅 演练:使用本机代码创建Request-Level HTTP 模块。
可以使用调用约定编译代码, __stdcall (/Gz)
而不是为每个函数显式声明调用约定。
要求
类型 | 说明 |
---|---|
客户端 | - Windows Vista 上的 IIS 7.0 - Windows 7 上的 IIS 7.5 - Windows 8 上的 IIS 8.0 - Windows 10 上的 IIS 10.0 |
服务器 | - Windows Server 2008 上的 IIS 7.0 - Windows Server 2008 R2 上的 IIS 7.5 - Windows Server 2012 上的 IIS 8.0 - Windows Server 2012 R2 上的 IIS 8.5 - Windows Server 2016 上的 IIS 10.0 |
产品 | - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0 - IIS Express 7.5、IIS Express 8.0、IIS Express 10.0 |
Header | Httpserv.h |