// ------------------------------------------------------------------------------------------------
// CHttpFilterConnHandler::MHFRunL
// Process a transaction event.
// ------------------------------------------------------------------------------------------------
//
void CHttpFilterConnHandler::MHFRunL(RHTTPTransaction aTransaction,
                                     const THTTPEvent& aEvent)
{
    TInt state = 0;
    TInt gprsState = 0;
    TInt wcdmaState = 0;
    TApBearerType bearerType;

    if (aEvent.iStatus == THTTPEvent::ESubmit)
    {
        THTTPHdrVal isNewConn;
        RHTTPConnectionInfo	connInfo = iSession->ConnectionInfo();
        RStringPool strPool = aTransaction.Session().StringPool();
        TBool ret = connInfo.Property (strPool.StringF(HttpFilterCommonStringsExt::EHttpNewConnFlag,
                                       HttpFilterCommonStringsExt::GetTable()), isNewConn);

        if ( LocalHostCheckL(aTransaction) && !( ret && isNewConn.Type() == THTTPHdrVal::KTIntVal ) )
            {
            return;
            }

        THTTPHdrVal callback;
        RHTTPTransactionPropertySet propSet = aTransaction.PropertySet();
        RStringF callbackStr = strPool.StringF( HttpFilterCommonStringsExt::EConnectionCallback, 
            HttpFilterCommonStringsExt::GetTable() );

        MConnectionCallback* callbackPtr = NULL;
    
        // this is a transaction, already forwarded to download manager
        if( propSet.Property( callbackStr, callback ) )
        {
            callbackPtr = REINTERPRET_CAST( MConnectionCallback*, callback.Int() );
        }        
void UPPayHttpConnection::AddProxy()
{
	RHTTPTransactionPropertySet transactionProperties = iTransaction.PropertySet();
	_LIT8(KAddress,"10.0.0.172:80");
	TBuf8<20> aProxy8(KAddress);
	RStringF prxAddr = iSession.StringPool().OpenFStringL(aProxy8);
	CleanupClosePushL(prxAddr);

	THTTPHdrVal prxUsage(iSession.StringPool().StringF(HTTP::EUseProxy, RHTTPSession::GetTable()));
	transactionProperties.SetPropertyL(iSession.StringPool().StringF(HTTP::EProxyUsage, RHTTPSession::GetTable()), prxUsage);
	transactionProperties.SetPropertyL(iSession.StringPool().StringF(HTTP::EProxyAddress, RHTTPSession::GetTable()), prxAddr);

	CleanupStack::PopAndDestroy(); // prxAddr
}
void CTestTransaction::ConstructL(RHTTPSession& aSession)
	{
	TBool hasRequestBody = EFalse;

	switch (iTransactionType)
		{
		case HTTP::EPOST : 
		case HTTP::EPUT : 

			if (iFilename.Length() > 0)
				{
				User::LeaveIfError(SetFileNameL(iFilename));
				
				hasRequestBody = ETrue;
				}
		break ;
		
		case HTTP::EGET :
		case HTTP::EDELETE:
		case HTTP::EHEAD:
		case HTTP::ECONNECT :
		default:
		;
		}
	
	TUriParser8 KURI;
	KURI.Parse(iUri);		

	RStringPool strPool = aSession.StringPool();
	
	//	open a transaction within the required session and use the class callback object for 
	//	managing the subsequent events...

	iTransaction = aSession.OpenTransactionL(KURI, *this, strPool.StringF(iTransactionType, RHTTPSession::GetTable()));

	iState = EActive;
	
	RHTTPRequest request = iTransaction.Request();

	RHTTPHeaders headers = request.GetHeaderCollection();
	
	AddAcceptHeaderL(headers, strPool);

	SetUserAgentL(headers, strPool);

	SetContentLengthL(headers, strPool);

	AcceptEncodingL(headers, strPool);
	
	// Check to see if pipelining should be disabled

	if (Machine()->GetDefine(KITHDisablePipelining).CompareF(KITHYes)==0)
		{
		RHTTPTransactionPropertySet transactionPropertySet = iTransaction.PropertySet();
		RStringF name = strPool.StringF(HTTP::EHttpPipelining, RHTTPSession::GetTable());
		RStringF value = strPool.StringF(HTTP::EDisablePipelining,RHTTPSession::GetTable());
		transactionPropertySet.SetPropertyL(name,value);
		}
	
	

	//	Add request body
	if (hasRequestBody)
		{
		if (!AddRequestBodyL(headers, strPool))
			User::LeaveIfError(KErrArgument);
		}
	}
//------------------------------------------------------------------------
// 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;
                        }
			
		}
	}
}