기존 HTTP 요청 본문에 새 엔터티 본문을 삽입합니다.
구문
virtual HRESULT InsertEntityBody(
IN VOID* pvBuffer,
IN DWORD cbBuffer
) = 0;
매개 변수
pvBuffer
[IN] 요청 엔터티 본문을 포함하는 버퍼에 대한 포인터 VOID 입니다.
cbBuffer
[IN] DWORD 버퍼의 크기(바이트)를 포함하는 입니다.
반환 값
HRESULT입니다. 가능한 값에는 다음 표에 있는 값이 포함되지만, 이에 국한되는 것은 아닙니다.
| 값 | 설명 |
|---|---|
| S_OK | 작업이 성공했음을 나타냅니다. |
설명
InsertEntityBody 메서드는 매개 변수가 가리키는 pvBuffer 엔터티 본문을 HTTP 요청 엔터티 본문에 삽입합니다.
참고
새 엔터티 본문의 삽입 지점은 웹 클라이언트에서 나중에 검색할 수 있는 나머지 읽지 않은 엔터티 본문 앞에 있습니다.
중요
IIS는 엔터티 본문 버퍼의 복사본을 만들지 않습니다. 모듈의 엔터티 버퍼는 요청이 끝날 때까지 보존되어야 합니다.
이 메서드는 Content-Length 헤더 값을 업데이트하지 않습니다. 이 메서드를 사용하는 모듈은 Content-Length를 별도로 업데이트해야 합니다.
예제
다음 코드 예제에서는 IHttpContext::AllocateRequestMemory 메서드를 호출하여 1KB 버퍼를 할당하는 HTTP 모듈을 만드는 방법을 보여 줍니다. 그런 다음 모듈은 "헬로 월드" 문자열을 버퍼에 복사합니다. 마지막으로 모듈은 메서드를 InsertEntityBody 호출하여 미리 로드된 HTTP 요청 엔터티 본문을 버퍼로 바꾼 다음 종료합니다.
#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <httpserv.h>
// NOTE - Data needs to be passed to this module, e.g. a POST request, or it will not appear to return anything.
// Create the module class.
class MyHttpModule : public CHttpModule
{
public:
REQUEST_NOTIFICATION_STATUS
OnBeginRequest(
IN IHttpContext * pHttpContext,
IN IHttpEventProvider * pProvider
)
{
// Create an HRESULT to receive return values from methods.
HRESULT hr;
// Allocate a 1K buffer.
DWORD cbBuffer = 1024;
void * pvBuffer = pHttpContext->AllocateRequestMemory(cbBuffer);
// Test for an error.
if (NULL == pvBuffer)
{
// Set the error status.
pProvider->SetErrorStatus(
HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY));
// End additional processing.
return RQ_NOTIFICATION_FINISH_REQUEST;
}
// Copy a string into the buffer.
strcpy_s((char*)pvBuffer,cbBuffer,"Hello world!");
// Insert the entity body into the buffer.
hr = pHttpContext->GetRequest()->InsertEntityBody(
pvBuffer,(DWORD)strlen((char*)pvBuffer));
// Test for an error.
if (FAILED(hr))
{
// Set the error status.
pProvider->SetErrorStatus( hr );
// End additional processing.
return RQ_NOTIFICATION_FINISH_REQUEST;
}
// 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 );
// Set the request notifications and exit.
return pModuleInfo->SetRequestNotifications(
new MyHttpModuleFactory,
RQ_BEGIN_REQUEST,
0
);
}
모듈은 RegisterModule 함수를 내보내야 합니다. 프로젝트에 대한 모듈 정의(.def) 파일을 만들어 이 함수를 내보내거나 스위치를 사용하여 /EXPORT:RegisterModule 모듈을 컴파일할 수 있습니다. 자세한 내용은 연습: 네이티브 코드를 사용하여 Request-Level HTTP 모듈 만들기를 참조하세요.
필요에 따라 각 함수에 대한 호출 규칙을 명시적으로 선언하는 대신 호출 규칙을 사용하여 __stdcall (/Gz) 코드를 컴파일할 수 있습니다.
요구 사항
| 형식 | Description |
|---|---|
| 클라이언트 | - 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 |
| 헤더 | Httpserv.h |