nsHTTPResponseListener::OnDataAvailable(nsIChannel* channel, nsISupports* context, nsIInputStream *i_pStream, PRUint32 i_SourceOffset, PRUint32 i_Length)
nsHTTPCacheListener::OnDataAvailable(nsIChannel *aChannel, nsISupports *aContext, nsIInputStream *aStream, PRUint32 aSourceOffset, PRUint32 aCount)
nsHTTPResponseListener::OnDataAvailable(nsIChannel* channel,                                        nsISupports* context,                                        nsIInputStream *i_pStream,                                         PRUint32 i_SourceOffset,                                        PRUint32 i_Length){    nsresult rv = NS_OK;    PRUint32 actualBytesRead;    NS_ASSERTION(i_pStream, "No stream supplied by the transport!");    nsCOMPtr<nsIBufferInputStream> bufferInStream = do_QueryInterface(i_pStream);    PR_LOG(gHTTPLog, PR_LOG_ALWAYS,            ("nsHTTPResponseListener::OnDataAvailable [this=%x].\n"            "\tstream=%x. \toffset=%d. \tlength=%d.\n",            this, i_pStream, i_SourceOffset, i_Length));    if (!mResponse)    {        mResponse = new nsHTTPResponse ();        if (!mResponse) {            NS_ERROR("Failed to create the response object!");            return NS_ERROR_OUT_OF_MEMORY;        }        NS_ADDREF(mResponse);        mChannel->SetResponse(mResponse);    }    //    // Parse the status line and the response headers from the server    //    if (!mHeadersDone) {        //        // Parse the status line from the server.  This is always the         // first line of the response...        //        if (!mFirstLineParsed) {            rv = ParseStatusLine(bufferInStream, i_Length, &actualBytesRead);            NS_ASSERTION(i_Length - actualBytesRead <= i_Length, "wrap around");            i_Length -= actualBytesRead;        }        PR_LOG(gHTTPLog, PR_LOG_ALWAYS,                ("\tOnDataAvailable [this=%x]. Parsing Headers\n", this));        //        // Parse the response headers as long as there is more data and        // the headers are not done...        //        while (NS_SUCCEEDED(rv) && i_Length && !mHeadersDone) {            rv = ParseHTTPHeader(bufferInStream, i_Length, &actualBytesRead);            NS_ASSERTION(i_Length - actualBytesRead <= i_Length, "wrap around");            i_Length -= actualBytesRead;        }        if (NS_FAILED(rv)) return rv;                // Don't do anything else until all headers have been parsed        if (!mHeadersDone)            return NS_OK;        //        // All the headers have been read.        //        rv = FinishedResponseHeaders();        if (NS_FAILED(rv)) return rv;    }    // At this point we've digested headers from the server and we're    // onto the actual data. If this transaction was initiated without    // an AsyncRead, we just want to pass the OnData() notifications    // straight through to the consumer.    //    // .... otherwise...    //    // if we were AsyncOpened, we want to increment our internal byte count    // so when we finally push the stream to the consumer via AsyncRead,    // we're sure to pass him all the data that has queued up.    if (mChannel->mOpenObserver && !mResponseDataListener) {        mBytesReceived += i_Length;        mDataStream = i_pStream;    } else {        //        // Abort the connection if the consumer has been released.  This will         // happen if a redirect has been processed...        //        if (!mResponseDataListener) {            // XXX: What should the return code be?            rv = NS_BINDING_ABORTED;        }        if (NS_SUCCEEDED(rv)) {            if (i_Length) {                PR_LOG(gHTTPLog, PR_LOG_ALWAYS,                        ("\tOnDataAvailable [this=%x]. Calling consumer "                        "OnDataAvailable.\tlength:%d\n", this, i_Length));                rv = mResponseDataListener->OnDataAvailable(mChannel, mChannel->mResponseContext,                                                            i_pStream, 0, i_Length);                if (NS_FAILED(rv)) {                  PR_LOG(gHTTPLog, PR_LOG_ERROR,                          ("\tOnDataAvailable [this=%x]. Consumer failed!"                          "Status: %x\n", this, rv));                }            }        }     } // end !mChannel->mOpenObserver    return rv;}