Take good care of reading exact the pECB.cbTotalBytes of data. If you read less bytes than indicated in pECB.cbTotalBytes a 'Connection reset by peer' error occurs in the browser.
function HttpExtensionProc (var pECB: EXTENSION_CONTROL_BLOCK) : DWORD; export; stdcall;
var
Data : Array[0..4096] of Char;
Response : Array[0..8] of Char;
dwLen, ToRead : DWord;
begin
...
// Do something with the pECB.cbAvailable Bytes in pECB.lpbData
...
// How many bytes left to read?
ToRead:=pECB.cbTotalBytes - pECB.cbAvailable;
// Our data buffer is limited to 4kByte - dwLen is set to it or the rest
if ToRead > 4096 then dwLen := 4096 else dwLen := ToRead;
// Call ReadClient until all Bytes are read
while (ToRead > 0) and pECB.ReadClient(pECB.ConnID, @Data, @dwLen) do begin
...
// Do something with the dwLen Bytes in Data
...
// dwLen now contains the read count
Dec(ToRead, dwLen);
// Set dwLen again for the next read request
if ToRead > 4096 then dwLen := 4096 else dwLen := ToRead;
end;
// Initialize the response header
StrPCopy(Response, '200 OK');
pECB.ServerSupportFunction(pECB.ConnID, HSE_REQ_SEND_RESPONSE_HEADER, @Response, nil, nil);
// We've done it
result := HSE_STATUS_SUCCESS;
end;
You can easily use the integrated debugger of Delphi/C++ builder when you follow this instructions:
Some options are new in the ISAPI handler since server version 1.1: