applayerprotocols/httptransportfw/Test/T_HttpOnline/t_100continuetest_2.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "t_100continuetest.h"
       
    17 
       
    18 CTestClient_2* CTestClient_2::NewL(TInt aTestNumber, CScriptFile* aIniSettingsFile)
       
    19 	{
       
    20 	CTestClient_2* self = new(ELeave)CTestClient_2(aTestNumber, aIniSettingsFile);
       
    21 	CleanupStack::PushL(self);
       
    22 	CleanupStack::Pop(self);
       
    23 	return self;
       
    24 	}
       
    25 
       
    26 CTestClient_2::~CTestClient_2()
       
    27 	{
       
    28 	}
       
    29 
       
    30 CTestClient_2::CTestClient_2(TInt aTestNumber, CScriptFile* aIniSettingsFile) :
       
    31 	iIniSettingsFile(aIniSettingsFile),
       
    32 	iTestNumber(aTestNumber)
       
    33 	{
       
    34 	}
       
    35 
       
    36 void CTestClient_2::DoRunL()
       
    37 	{
       
    38 	// Open the HTTP session
       
    39 	iSession.OpenL();
       
    40 	CleanupClosePushL(iSession);
       
    41 
       
    42 	RStringPool strP = iSession.StringPool();
       
    43 	TUriParser8 up;
       
    44 	up.Parse(KHttpUrl);
       
    45 
       
    46 	RHTTPTransaction trans = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EPOST,RHTTPSession::GetTable()));
       
    47 	
       
    48 	RHTTPHeaders hdr = trans.Request().GetHeaderCollection();
       
    49 	RStringF ct = strP.StringF(HTTP::EContentType, RHTTPSession::GetTable());
       
    50 	RStringF ctValStrF = strP.OpenFStringL(_L8("text/html"));
       
    51 	CleanupClosePushL(ctValStrF);
       
    52 	THTTPHdrVal ctVal;
       
    53 	ctVal.SetStrF(ctValStrF);
       
    54 	hdr.SetFieldL(ct, ctVal);
       
    55 	CleanupStack::PopAndDestroy(&ctValStrF);
       
    56 	
       
    57 	RHTTPTransactionPropertySet propSet = trans.PropertySet();
       
    58 	RStringF notifyContinue = strP.StringF(HTTP::ENotify100Continue, RHTTPSession::GetTable());
       
    59 	RStringF enableNotification = strP.StringF(HTTP::EEnableNotification, RHTTPSession::GetTable());
       
    60 	THTTPHdrVal val(enableNotification);
       
    61 	propSet.SetPropertyL(notifyContinue, val);
       
    62 	
       
    63 	trans.Request().SetBody(*this);
       
    64 	
       
    65 	trans.SubmitL();
       
    66 	CActiveScheduler::Start();
       
    67 	
       
    68 	CleanupStack::PopAndDestroy(&iSession); //close iSession
       
    69 	}
       
    70 
       
    71 
       
    72 TInt CTestClient_2::RunError(TInt aErr)
       
    73 	{
       
    74 	iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr);
       
    75 	return KErrNone;
       
    76 	}
       
    77 
       
    78 void CTestClient_2::DoCancel()
       
    79 	{
       
    80 	}
       
    81 
       
    82 const TDesC& CTestClient_2::TestName()
       
    83 	{
       
    84 	_LIT(KHeaderTestName,"100-Continue Test: 2");
       
    85 	return KHeaderTestName;
       
    86 	}
       
    87 
       
    88 TInt CTestClient_2::MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& /*aEvent*/)
       
    89 	{
       
    90 	_LIT(KLogDescription, "\nTest failed with error code %d on transaction ID=%d\n");
       
    91 	iEngine->Utils().LogIt(KLogDescription, aError, aTransaction.Id());
       
    92 	iFailureError = aError;
       
    93 	CActiveScheduler::Stop();
       
    94 	return KErrNone;
       
    95 	}
       
    96 
       
    97 void CTestClient_2::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
       
    98 	{
       
    99 	switch (aEvent.iStatus)
       
   100 		{
       
   101 		case THTTPEvent::EGotResponseHeaders:
       
   102 			{
       
   103 			} break;
       
   104 		case THTTPEvent::ESubmit:
       
   105 			{
       
   106 			} break;
       
   107 		case THTTPEvent::EGotResponseBodyData:
       
   108 			{
       
   109 			MHTTPDataSupplier* data = aTransaction.Response().Body();
       
   110 			data->ReleaseData();
       
   111 			} break;
       
   112 		case THTTPEvent::EResponseComplete:
       
   113 			{
       
   114 			} break;
       
   115 		case THTTPEvent::ESucceeded:
       
   116 			{
       
   117 			aTransaction.Close();
       
   118 			CActiveScheduler::Stop();
       
   119 			}
       
   120 			break;
       
   121 		case THTTPEvent::EFailed:
       
   122 			{
       
   123 			aTransaction.Close();
       
   124 			CActiveScheduler::Stop();
       
   125 			} break;
       
   126 		case THTTPEvent::EReceived100Continue:
       
   127 			{
       
   128 			iEngine->Utils().LogIt(_L("Recevied 100-Continue response notification"));	
       
   129 			}break;
       
   130 		default:
       
   131 			{
       
   132 			_LIT(KLogDescription, "<unrecognised event> %d");
       
   133 			iEngine->Utils().LogIt(KLogDescription,aEvent.iStatus);
       
   134 			if (aEvent.iStatus < 0)
       
   135 				{
       
   136 				iFailureError = aEvent.iStatus;
       
   137 				CActiveScheduler::Stop();
       
   138 				}
       
   139 			} 
       
   140 			break;
       
   141 		}
       
   142 	
       
   143 	return;
       
   144 	}
       
   145 
       
   146 TBool CTestClient_2::GetNextDataPart(TPtrC8& aDataPart)
       
   147 	{
       
   148 	aDataPart.Set(KBody());	
       
   149 	return ETrue;
       
   150 	}
       
   151 
       
   152 void CTestClient_2::ReleaseData()
       
   153 	{
       
   154 		
       
   155 	}
       
   156 
       
   157 TInt CTestClient_2::OverallDataSize()
       
   158 	{
       
   159 	return (12);
       
   160 	}
       
   161 
       
   162 TInt CTestClient_2::Reset()
       
   163 	{
       
   164 	return KErrNotSupported;	
       
   165 	}	
       
   166 
       
   167