Metodo IHttpResponse::WriteEntityChunks
Aggiunge una o più strutture HTTP_DATA_CHUNK al corpo della risposta.
Sintassi
virtual HRESULT WriteEntityChunks(
IN HTTP_DATA_CHUNK* pDataChunks,
IN DWORD nChunks,
IN BOOL fAsync,
IN BOOL fMoreData,
OUT DWORD* pcbSent,
OUT BOOL* pfCompletionExpected = NULL
) = 0;
Parametri
pDataChunks
[IN] Puntatore a una o più HTTP_DATA_CHUNK
strutture.
nChunks
[IN] Oggetto DWORD
contenente il numero di blocchi a cui punta pDataChunks
.
fAsync
[IN] true
se il metodo deve completare in modo asincrono; in caso contrario, false
.
fMoreData
[IN] true
se nella risposta devono essere inviati altri dati; false
se si tratta dell'ultimo dato.
pcbSent
[OUT] Numero di byte inviati al client se la chiamata viene completata in modo sincrono.
pfCompletionExpected
[OUT] true
se un completamento asincrono è in sospeso per questa chiamata; in caso contrario, false
.
Valore restituito
Oggetto HRESULT
. I valori possibili includono, ma non sono limitati a, quelli indicati nella tabella seguente.
Valore | Descrizione |
---|---|
S_OK | Indica che l'operazione ha avuto esito positivo. |
ERROR_INVALID_PARAMETER | Indica che il parametro non è valido, ad esempio il pDataChunks puntatore è impostato su NULL. |
ERROR_NOT_ENOUGH_MEMORY | Indica che la memoria non è sufficiente per eseguire l'operazione. |
ERROR_ARITHMETIC_OVERFLOW | Più di 65535 blocchi sono stati aggiunti alla risposta. |
Commenti
Gli sviluppatori possono usare il WriteEntityChunks
metodo per inserire una singola struttura o una matrice HTTP_DATA_CHUNK
di HTTP_DATA_CHUNK
strutture nel corpo della risposta. Se l'operazione è stata completata in modo sincrono, il parametro riceverà il pcbSent
numero di byte inseriti nella risposta.
Se il buffering è attivato, il WriteEntityChunks
metodo creerà una copia di qualsiasi HTTP_DATA_CHUNK
struttura, duplicando quindi i dati sottostanti in modo che non sia necessario conservare. Se il buffering viene disattivato o viene raggiunto il limite del buffer di risposta, il WriteEntityChunks
metodo scarica anche la risposta. Se il buffer è disattivato e il fAsync
parametro è true
, la memoria deve essere mantenuta fino al completamento della richiesta.
È possibile configurare un'operazione WriteEntityChunks
per completare in modo asincrono impostando il fAsync
parametro su true
. In questa situazione, il WriteEntityChunks
metodo restituirà immediatamente al chiamante e il parametro non riceverà il pcbSent
numero di byte inseriti nella risposta. Se il buffering è disabilitato e il parametro è true
, la memoria per il fAsync
pDataChunks
parametro deve essere persistente fino al completamento della chiamata asincrona.
Un massimo di 65535 blocchi (64 KB meno 1) può essere scritto in una richiesta.
Esempio
Nell'esempio seguente viene illustrato come usare il WriteEntityChunks
metodo per creare un modulo HTTP che inserisce una matrice di due blocchi di dati nella risposta. L'esempio restituisce quindi la risposta a un client Web.
#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 );
// Create an HRESULT to receive return values from methods.
HRESULT hr;
// Create an array of data chunks.
HTTP_DATA_CHUNK dataChunk[2];
// Buffer for bytes written of data chunk.
DWORD cbSent;
// Create string buffers.
PCSTR pszOne = "First chunk data\n";
PCSTR pszTwo = "Second chunk data\n";
// Retrieve a pointer to the response.
IHttpResponse * pHttpResponse = pHttpContext->GetResponse();
// Test for an error.
if (pHttpResponse != NULL)
{
// Clear the existing response.
pHttpResponse->Clear();
// Set the MIME type to plain text.
pHttpResponse->SetHeader(
HttpHeaderContentType,"text/plain",
(USHORT)strlen("text/plain"),TRUE);
// Set the chunk to a chunk in memory.
dataChunk[0].DataChunkType = HttpDataChunkFromMemory;
// Set the chunk to the first buffer.
dataChunk[0].FromMemory.pBuffer =
(PVOID) pszOne;
// Set the chunk size to the first buffer size.
dataChunk[0].FromMemory.BufferLength =
(USHORT) strlen(pszOne);
// Set the chunk to a chunk in memory.
dataChunk[1].DataChunkType = HttpDataChunkFromMemory;
// Set the chunk to the second buffer.
dataChunk[1].FromMemory.pBuffer =
(PVOID) pszTwo;
// Set the chunk size to the second buffer size.
dataChunk[1].FromMemory.BufferLength =
(USHORT) strlen(pszTwo);
// Insert the data chunks into the response.
hr = pHttpResponse->WriteEntityChunks(
dataChunk,2,FALSE,TRUE,&cbSent);
// 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
);
}
Il modulo deve esportare la funzione RegisterModule . È possibile esportare questa funzione creando un file di definizione del modulo (con estensione def) per il progetto oppure è possibile compilare il modulo usando l'opzione /EXPORT:RegisterModule
. Per altre informazioni, vedere Procedura dettagliata: Creazione di un modulo HTTP Request-Level tramite codice nativo.
Facoltativamente, è possibile compilare il codice usando la __stdcall (/Gz)
convenzione chiamante anziché dichiarare esplicitamente la convenzione chiamante per ogni funzione.
Requisiti
Tipo | Descrizione |
---|---|
Client | - IIS 7.0 in Windows Vista - IIS 7.5 in Windows 7 - IIS 8.0 in Windows 8 - IIS 10.0 in Windows 10 |
Server | - IIS 7.0 in Windows Server 2008 - IIS 7.5 in Windows Server 2008 R2 - IIS 8.0 in Windows Server 2012 - IIS 8.5 in Windows Server 2012 R2 - IIS 10.0 in Windows Server 2016 |
Prodotto | - 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 |
Intestazione | Httpserv.h |
Vedere anche
Interfaccia IHttpResponse
Metodo IHttpResponse::WriteEntityChunkByReference
Commenti e suggerimenti
https://aka.ms/ContentUserFeedback.
Presto disponibile: Nel corso del 2024 verranno gradualmente disattivati i problemi di GitHub come meccanismo di feedback per il contenuto e ciò verrà sostituito con un nuovo sistema di feedback. Per altre informazioni, vedereInvia e visualizza il feedback per