void CHttpClientFilter::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) { switch( aEvent.iStatus ) { case THTTPEvent::ESubmit: { AlterRequestHeadersL(aTransaction); } break; case THTTPEvent::EGotResponseHeaders: { AlterResponseHeadersL(aTransaction); } break; case KErrHttpNonPipeliningError: case KErrHttpPipeliningError: { // This transaction was being pipelined when an error occurred. Need to // cancel and then re-submit. aTransaction.Cancel(); aTransaction.SubmitL(); } break; default: break; } }
// ------------------------------------------------------------------------------------------------ // CHttpFilterProxy::MHFRunL // Process a transaction event. // ------------------------------------------------------------------------------------------------ // void CHttpFilterProxy::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) { switch(aEvent.iStatus) { case THTTPEvent::ESubmit: { if (LocalHostCheckL(aTransaction, iStringPool)) { return; } SetProxyL(aTransaction); } break; case KErrNotReady: { if (LocalHostCheckL(aTransaction, iStringPool)) { return; } if(iFilterOwnsConnection) { // we must re-start the RConnection TInt err = iConnection.Start(); if (err == KErrAlreadyExists) { // the KErrNotReady must have come from elsewhere return; } User::LeaveIfError(err); // re-submit the transaction aTransaction.Cancel(); aTransaction.SubmitL(); } break; } default: break; } }
void CHttpClientTransactionImpl::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) { __ASSERT_DEBUG (iTransaction == aTransaction, User::Invariant()); switch(aEvent.iStatus) { case THTTPEvent::EGotResponseHeaders: { // Parse the headers if(aTransaction.Response().GetHeaderCollection().iImplementation->ConvertAllHeadersToParsedFormat() != KErrNone) { iClientTrans.OnError(KErrCorrupt); // Change the error code. return; } iClientTrans.OnResponseHeaders(); if(iDataReceiver) { iDataReceiver->SetDataSupplier(aTransaction.Response().Body()); } } break; case THTTPEvent::EGotResponseBodyData: { iDataReceiver->DataAvailable(); } break; case THTTPEvent::ERedirectedTemporarily: case THTTPEvent::ERedirectedPermanently: { if(!iClientTrans.OnRedirection()) { aTransaction.Cancel(); } } break; case THTTPEvent::ERedirectRequiresConfirmation: { aTransaction.Cancel(); if(iClientTrans.OnRedirection()) { aTransaction.Submit(); } // Otherwise no need to do anything. Response will complete by itself } break; case THTTPEvent::EResponseComplete: // Do nothing break; case THTTPEvent::ESucceeded: { iClientTrans.OnCompletion(); } break; case THTTPEvent::EFailed: { // Cancel the transaction. The failure would have been indicated to the // client already. iTransaction.Cancel(); } break; case THTTPEvent::ESendTimeOut: { } break; case THTTPEvent::EReceiveTimeOut: { iTransaction.Cancel(); iClientTrans.OnError(KErrHttpResponseNotReceived); } break; default: { iClientTrans.OnError(aEvent.iStatus); } break; } }
//------------------------------------------------------------------------ // CTestFilter::CheckHeadersL // Check HTTP headers and extract MIME type //------------------------------------------------------------------------ // void CTestFilter::CheckHeadersL( RHTTPTransaction& aTrans ) { // read the header data and check the MIME type here // check the status and body RHTTPResponse response = aTrans.Response(); TInt status = response.StatusCode(); THTTPHdrVal fieldVal; // check if status == 401 and realm is 3GPP then we need to bootstrap, if we are already bootstrappign this is the second call if( status == HTTPStatus::EUnauthorized ) { TInt headerPart=0; THTTPHdrVal headerVal; RStringF wwwAuthHeader = iStringPool.StringF(HTTP::EWWWAuthenticate,RHTTPSession::GetTable()); RHTTPHeaders headers(aTrans.Response().GetHeaderCollection()); RString realm; THTTPHdrVal hdrVal; if (!headers.GetParam(wwwAuthHeader, iStringPool.StringF(HTTP::ERealm,RHTTPSession::GetTable()), hdrVal, headerPart)) { realm = hdrVal; const TDesC8& val = realm.DesC(); if (headerPart == KErrNotFound) return; THTTPHdrVal authTypeParam; RHTTPTransactionPropertySet propSet = aTrans.PropertySet(); // if we are already bootstrapping results will be retrieved when request is resubmitted iBootstrapPending = ETrue; TTimeIntervalMicroSeconds32 aInterval(20000000); iTimeOut->Start(aInterval); //Start the http post request timer, aInterval - timeout in micro-seconds if(!iBootstrapWait.IsStarted()) { iBootstrapWait.Start(); } if( iHaveCredentials ) { RHTTPTransactionPropertySet propSet = aTrans.PropertySet(); //user name/pass word for accessing http://replab.nrln.net/digest/ //username: dummy, password: dummy TBuf8<KB64KeySize> keyBase64(_L8("Aladdin")); TBuf8<KB64KeySize> keyBase64Username(_L8("open sesame"));; RString username = iStringPool.OpenStringL( keyBase64 ); CleanupClosePushL<RString>( username ); RString password = iStringPool.OpenStringL( keyBase64Username ); CleanupClosePushL<RString>( password ); propSet.SetPropertyL( iUsernameStr, username ); propSet.SetPropertyL( iPasswordStr, password ); CleanupStack::PopAndDestroy(&password); CleanupStack::PopAndDestroy(&username); //Cancel the transaction aTrans.Cancel(); // Re-submit the http request with much needed credentials aTrans.SubmitL(); } else { //Since bootstrapping failed,Do not have to resubmit the http request ? return; } } } }