Article View: comp.os.ms-windows.programmer.networks
Article #32Problem with ISAPI Filter response
From: Jean-Marc
Date: Thu, 06 Jul 2000 00:00
Date: Thu, 06 Jul 2000 00:00
70 lines
4091 bytes
4091 bytes
I'm writing an ISAPI Filter for IIS4 or 5 that is supposed to add some
source code inside an HTML page that has to be served. It increases the size
of the page of 1 or 2 Ko.
I've caught the SF_NOTIFY_SEND_RAW_DATA event to add my code in several
places of the HTML source of the page.
I know the handler is called 2 times for each file sent to the browser.
- 1 - to send the header (with the page size)
- 2 - to send the data
The first time I adjust the size of the "content-length" field of the
header.
The second time I put my own HTML code inside the page in a new buffer
bigger than the buffer provided in the HTTP_FILTER_RAW_DATA instance
provided by the framework. So I replace it by a new buffer assigned by the
AllocMem() function, I change the pRawData->pvInData and the
pRawData->cbInData values to the new values.
But my browser keeps waiting for the end of the page to be sent. I checked
everything about the sizes and it is good. I must miss something but I don't
know what. Some help would be very appreciated. Thanks in advance. I further
provide some of my code to better visualize the function...
-----
Jean-Marc Geindre
filter.cpp
DWORD CMy2Filter::OnSendRawData(CHttpFilterContext* pCtxt,
PHTTP_FILTER_RAW_DATA pRawData)
{
// is it HTML (Allocated on OnMapUrl() ) ?
if (pCtxt->m_pFC->pFilterContext) {
char *buffer=(char *)pRawData->pvInData;
if (strstr(buffer,"HTTP/1"))
{
// Is it the Header to be sent ?
char *before=strstr(buffer,"Content-Length: ");
// ...
// I change the numeric val of content-length
// copy the size into the buffer
sprintf(buffer, "%s%d%s", before, iSize, after);
// I save the size for the next call of the handler
// The buffer has been allocated with the size of 1*sizeof(int)
// in the OnMapUrl() handler with AllocMem()
int *ptr=(int *)(pCtxt->m_pFC->pFilterContext);
ptr[0]=iSize;
}
} else {
// Second call, the content-length has been modified the prev call
char *newBuffer;
// I get the size from pFilterContext filled the first time
int *iTmpBuf=(int *)pCtxt->m_pFC->pFilterContext;
int newBufLength=iTmpBuf[0];
newBuffer=(CHAR*)pCtxt->AllocMem(newBufLength, (DWORD)NULL);
memset(newBuffer, ' ', newBufLength);
int indexBuffer=0;
//...
// I put my codes
// ...
// I close the buffer like a normal string
newBuffer[newBufLength]=NULL;
// Copy of the new buffer
pRawData->pvInData=(void*)newBuffer;
pRawData->cbInData=newBufLength;
pCtxt->m_pFC->pFilterContext=NULL;
}
}
return SF_STATUS_REQ_NEXT_NOTIFICATION;
}
Technical Details
Message-ID:
<8k23m3$o4b$1@news2.isdnet.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1138df,d2eded122a034945,start X-Google-Attributes: gid1138df,public X-Google-Thread: 12729d,d2eded122a034945,start X-Google-Attributes: gid12729d,public X-Google-Thread: ff79f,d2eded122a034945,start X-Google-Attributes: gidff79f,public X-Google-Thread: f4d39,d2eded122a034945,start X-Google-Attributes: gidf4d39,public X-Google-Thread: f5082,d2eded122a034945,start X-Google-Attributes: gidf5082,public X-Google-Thread: 1089a1,d2eded122a034945,start X-Google-Attributes: gid1089a1,public X-Google-Thread: fbd5d,d2eded122a034945,start X-Google-Attributes: gidfbd5d,public X-Google-Thread: fa91f,d2eded122a034945,start X-Google-Attributes: gidfa91f,public From: "Jean-Marc" <jmgeindre@ifrance.com> Subject: Problem with ISAPI Filter response Date: 2000/07/06 Message-ID: <8k23m3$o4b$1@news2.isdnet.net> X-Deja-AN: 643062790 X-Trace: news2.isdnet.net 962892291 24715 195.154.181.98 (6 Jul 2000 14:04:51 GMT) X-MSMail-Priority: Normal X-Priority: 3 NNTP-Posting-Date: 6 Jul 2000 14:04:51 GMT Newsgroups: comp.os.ms-windows.programmer.networks,comp.os.ms-windows.programmer.tools.mfc,fr.comp.os.ms-windows.winnt,microsoft.public.fr.iis,microsoft.public.fr.vc,microsoft.public.inetserver.iis,microsoft.public.jp.visualc,microsoft.public.platformsdk.inter X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 X-Complaints-To: abuse@isdnet.net