locked
C++ Native module - No Entity data in OnSendResponse RRS feed

  • Question

  • User-1422594334 posted
    Hello,

    I want to retrieve the static content of a web page, either HTML or ASPX , and look for a particular tag/comment. My module is a native module written in C++. I have my module registered for the RQ_SEND_RESPONSE hr = pModuleInfo->SetRequestNotifications(pFactory,RQ_SEND_RESPONSE,0); The request notification is being fired up and the method of my module is being called. I am able to retrieve the headers, say "Server", however i am not getting the body of the static HTML page. As I matter of fact I am getting 0 on the EntityChunkCount. I am using IIS 7.5 and Visual Studio 2010.

    REQUEST_NOTIFICATION_STATUS CWebReaderHttpModule::OnSendResponse(IN IHttpContext* pHttpContext, IN ISendResponseProvider* pProvider )
    {
    HRESULT hResult;
    CModuleService moduleSvc;
    USHORT cchServerHeader;

    IHttpResponse* pHttpResponse = pHttpContext->GetResponse();

    if(pHttpResponse != NULL){
    if( pProvider->GetHeadersBeingSent() )
    this->pszServerHeader = pHttpResponse->GetHeader("Server",&cchServerHeader);

    HTTP_RESPONSE* httpResponse = pHttpResponse->GetRawHttpResponse();
    count = httpResponse->EntityChunkCount;
    moduleSvc.WriteEventViewerLog("response caught");
    return RQ_NOTIFICATION_CONTINUE;

    }

    if(pHttpResponse == NULL)
    return RQ_NOTIFICATION_FINISH_REQUEST;
    }

    Sunday, May 13, 2012 7:36 PM

All replies

  • User1084433844 posted

     I am faced to the same problem.

     My investigations showed that response data is in HttpDataChunkFromFileHandle and not HttpDataChunkFromMemory.

    I see event correct length.

    So, when I am trying to read it from the HANDLE, but get no data and GetLastError() indicates error 87

    ERROR_INVALID_PARAMETER
    87 (0x57)

    The parameter is incorrect.

    So I can't get my response body!

     

    My code is below.

    Please advice.

     

     

                if(rsp->EntityChunkCount > 0 && rsp->pEntityChunks) {

                    PHTTP_DATA_CHUNK hdc = rsp->pEntityChunks;
                    //HTTP_DATA_CHUNK_TYPE
                   
                    switch(hdc[0].DataChunkType) {
                    case HttpDataChunkFromMemory:

                                                  ....

                    case HttpDataChunkFromFileHandle:

                   

                        TRACE("\n HttpDataChunkFromFileHandle: ByteRange( Length=%d, StartingOffset=%d ) - FileHandle = %p\n",
                            hdc[0].FromFileHandle.ByteRange.Length,
                            hdc[0].FromFileHandle.ByteRange.StartingOffset,
                            hdc[0].FromFileHandle.FileHandle);
                        if(hdc[0].FromFileHandle.FileHandle == INVALID_HANDLE_VALUE) {
                            TRACE("\n HttpDataChunkFromFileHandle: INVALID_HANDLE_VALUE!\n");
                        } else {
                                    ....

                                                         readSuccess = ReadFile(hdc[0].FromFileHandle.FileHandle, readBuffer,
                                bytesToRead,
                                &byteReading, NULL);
                            if(!readSuccess) {

                                TRACE("after ReadFile - GetLastError=%ld\n", GetLastError());

                                             ...

     

     

    Tuesday, July 3, 2012 4:30 AM
  • User156223008 posted

    I have same problem.

    How can I modify the static .htm / .apsx content at OnSendResponse when pHttpDataChunk->DataChunkType == ::HttpDataChunkFromFileHandle?

    It works when pHttpDataChunk->DataChunkType == ::HttpDataChunkFromMemory then data is present in pHttpDataChunk->FromMemory.pBuffer 

    Hope someone have a solution.

    Thanks in advance Fritz

     

    Wednesday, December 16, 2015 12:54 PM