Example #1
0
void CHttpTestCaseGet12::OpenTestSessionL()
	{
	iSession.OpenL();
	iEngine->Utils().LogIt(_L("Session Created(Iteration 2 Get Test 12)"));
	iEngine->Utils().LogIt(_L("Session parameters: Default"));
	InstallAuthenticationL(iSession);
	iMyStrP = iSession.StringPool();

	// Literals used in the function
	_LIT8(KUrlPath,				"/http_tests/rc/401/private/index.html");

	// Replace the host name in the URL
	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestIPSection(), iIniSettingsFile);
	CleanupStack::PushL(newUrl8);
	TPtr8 newUrlPtr8 = newUrl8->Des();
	newUrlPtr8.Append(KUrlPath());

	TUriParser8 testURI;
	testURI.Parse(newUrlPtr8);
	
	iTransaction = iSession.OpenTransactionL(testURI, *this, iMyStrP.StringF(HTTP::EGET,RHTTPSession::GetTable()));
	iEngine->Utils().LogIt(_L("Transaction Created in Session"));
	iOpenTransactionCount++;

	//Get a handle of the request in iTransaction
	RHTTPRequest myRequest = iTransaction.Request();
	RHTTPHeaders myHeaders = myRequest.GetHeaderCollection();

	//provide  some headers 
	THTTPHdrVal acceptHdr(iMyStrP.StringF(HTTP::EAnyAny, RHTTPSession::GetTable()));
	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()),acceptHdr);
	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
	iEngine->Utils().LogIt(_L("Method:GET"));
	CleanupStack::PopAndDestroy(newUrl8);
	}
void CTestFilter::DoSubmitL( RHTTPTransaction aTransaction )
{
	RHTTPHeaders hdr = aTransaction.Request().GetHeaderCollection();
	
	RStringF fieldname = aTransaction.Session().StringPool().StringF(HTTP::EUserAgent,RHTTPSession::GetTable());
	
	TBool found = EFalse;
	TPtrC8 rawFieldData;
	
	hdr.GetRawField(fieldname, rawFieldData);
	
	found = rawFieldData.Find(iUserAgent.DesC()) != KErrNotFound;
	
	if(!found)
	    hdr.SetFieldL(fieldname, iUserAgent);
	
    if( iHaveCredentials )
        {
        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 );
		EncodeBasicAuthL(username, password, aTransaction);
        CleanupStack::PopAndDestroy(&password);
        CleanupStack::PopAndDestroy(&username);
        	
        }
}
void CHttpClientFilter::EnsureNoEndToEndHeadersInConnectionHeaderL(RHTTPTransaction aTransaction)
	{
	RHTTPHeaders headers = aTransaction.Request().GetHeaderCollection();
	RStringF connection = iStringPool.StringF(HTTP::EConnection,iStringTable);
	const TInt numConnectionHeaderParts = headers.FieldPartsL(connection);

	for( TInt ii = numConnectionHeaderParts - 1; ii >= 0; --ii ) 
		{
		// Examine connection-tokens from back to front so index is always valid. 
		// Check for an end to end header and remove it as a connection header
		// must not contain end to end headers.
		THTTPHdrVal value;
		TInt ret = headers.GetField(connection, ii, value);

		if( ( ret != KErrNotFound ) && ( value.Type() == THTTPHdrVal::KStrFVal ) )
			{
			RStringF valueStrF = value.StrF();
			if( valueStrF.Index(iStringTable) != HTTP::EClose  && 
				!IsHopByHopHeader(valueStrF) )
				{
				// The connection-token is not 'close' nor is it a end-to-end
				// header field name - remove it.
				User::LeaveIfError(headers.RemoveFieldPart(connection, ii)); 
				}
			}
		else
			{
			// The connection-token is not a hop-by-hop header field name -
			// remove it.
			User::LeaveIfError(headers.RemoveFieldPart(connection, ii));
			}			
		}
	}
Example #4
0
void CINC052596::ProcessHeadersL(RHTTPTransaction aTrans)
	{
	RStringF haaderName = aTrans.Session().StringPool().StringF(HTTP::EWWWAuthenticate, aTrans.Session().GetTable());
	THTTPHdrVal headerVal;
	RHTTPHeaders headers = aTrans.Response().GetHeaderCollection();
	User::LeaveIfError(headers.GetField(haaderName, 0, headerVal));
	}
Example #5
0
AMInt32 AMHttpSetOption(AMHttpRequest request, AMHttpOption option, 
    AMUInt8* inBuf, AMUInt32 inBufLen)
	{
	REINTERPRET( HttpConnectionInternal*, temp, request );
	RHTTPHeaders hdr = temp->Transaction->Request().GetHeaderCollection();
	
	HBufC8* buf = HBufC8::New( inBufLen );
	CleanupStack::PushL( buf );
	buf->Des().Append( inBuf, inBufLen );
	
	switch( option )
		{
		case AM_HTTP_TIMEOUT:
			{
			RStringF valStr = temp->session->StringPool().OpenFStringL( *buf );
			CleanupClosePushL(valStr);
			THTTPHdrVal val(valStr);
			hdr.SetFieldL(temp->session->StringPool().StringF(HTTP::EWspProxyConnectionTimeout,
			    RHTTPSession::GetTable()), val);
			CleanupStack::PopAndDestroy();  // valStr
			break;
			}
		}
	
	CleanupStack::PopAndDestroy( buf );
	}
void CHttpClientFilter::EnsureContentLengthL(RHTTPTransaction aTransaction)
	{
	RHTTPRequest request = aTransaction.Request();

	if( request.HasBody() )
		{
		THTTPHdrVal hdrVal;
		RStringF teName = iStringPool.StringF(HTTP::ETransferEncoding, iStringTable);

		// Get rid of Content-Length header if present
		// NOTE - cannot use a local variable for the Content-Length as causes a 
		// compiler bug in thumb builds - grand! : (
		RHTTPHeaders headers = request.GetHeaderCollection();
		headers.RemoveField(iStringPool.StringF(HTTP::EContentLength, iStringTable)); 
		
		TInt bodySize = request.Body()->OverallDataSize();
		if( bodySize != KErrNotFound )
			{
			// Size is known - set the ContentLength header.
			headers.SetFieldL(iStringPool.StringF(HTTP::EContentLength, iStringTable), THTTPHdrVal(bodySize));
			}
		else if( headers.GetField(teName, 0, hdrVal) == KErrNotFound )
			{
			// Size is unknown and there's been no Encoding indicated by the 
			// client - set the 'TransferEncoding: chunked'
			hdrVal.SetStrF(iStringPool.StringF(HTTP::EChunked, iStringTable));
			headers.SetFieldL(teName, hdrVal);
			}
		}
	}
Example #7
0
void CXmlHandler::AddRequestHeaderL(TInt aHdrField, const TDesC8& aHdrValue)
{
	RHTTPHeaders headers = iTransaction.Request().GetHeaderCollection();

	RStringF valStr = iSession.StringPool().OpenFStringL(aHdrValue);
	CleanupClosePushL(valStr);

	THTTPHdrVal val(valStr);
	headers.SetFieldL(iSession.StringPool().StringF(aHdrField, RHTTPSession::GetTable()), val);
	CleanupStack::PopAndDestroy(); // valStr
}
Example #8
0
void CHttpTestCase8::DoRunL()
	{
	// Literals used in the function
	_LIT8(KWapTestUrl,			"http://WapTestIP/perl/protected/dumpform.pl");

	// Replace the host name in the URL
	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile);
	CleanupStack::PushL(newUrl8);
	TPtr8 newUrlPtr8 = newUrl8->Des();

	TUriParser8 testURI;
	testURI.Parse(newUrlPtr8);

	//open a Session
	RHTTPSession mySession;
	mySession.OpenL();
	CleanupClosePushL(mySession);
	iEngine->Utils().LogIt(_L("Session Created(TC8)"));
	iEngine->Utils().LogIt(_L("Session parameters: Default"));
	// Install the authorisation plugin.
	InstallAuthenticationL(mySession);
	//Get the mySession'string pool handle;
	iMyStrP = mySession.StringPool();
	//Create , open and push in the CS a Transaction in mySession 
	RHTTPTransaction myTransaction;
	myTransaction = mySession.OpenTransactionL(testURI, *this, mySession.StringPool().StringF(HTTP::EPOST,RHTTPSession::GetTable()));
	CleanupClosePushL(myTransaction);
	iEngine->Utils().LogIt(_L("Transaction Created in mySession"));	
	//Get a handle of the request in myTransaction
	RHTTPRequest myRequest = myTransaction.Request();
	RHTTPHeaders myHeaders = myRequest.GetHeaderCollection();
	//  provide  some headers 
	THTTPHdrVal v2(iMyStrP.OpenFStringL(_L8("text/plain")));
	THTTPHdrVal v3(iMyStrP.OpenFStringL(_L8("text/html")));
	THTTPHdrVal v4(6);
	myHeaders.SetFieldL(iMyStrP.OpenFStringL(_L8("Accept")),v2 );
	myHeaders.SetFieldL(iMyStrP.OpenFStringL(_L8("Content-Type")), v3);
	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentLength, RHTTPSession::GetTable()),v4);
	iEngine->Utils().LogIt(_L("Testing Authentication. Method:Post"));
	myRequest.SetBody(*this);
	myTransaction.SubmitL();
	CActiveScheduler::Start();
	myTransaction.Close();
	iEngine->Utils().LogIt(_L("Transaction terminated\n"));
	mySession.Close();
	iEngine->Utils().LogIt(_L("Session terminated"));
	if (iTestFail==1)
		{
		User::Leave(-1);
		}
	CleanupStack::Pop(2); // mySession,myTansaction
	CleanupStack::PopAndDestroy(newUrl8);
	}
Example #9
0
void CHttpEventHandler::ParseCookieL(RHTTPTransaction& aTrans)
{
	RHTTPResponse response = aTrans.Response();
	RHTTPResponse resp = aTrans.Response();
	RStringPool pool = aTrans.Session().StringPool();
    RHTTPHeaders headers = resp.GetHeaderCollection();
    
	RStringF fieldName = pool.StringF(HTTP::ESetCookie,RHTTPSession::GetTable());
	
	_LIT(KSeparator,";");
	_LIT(KPathName,";path=");
	_LIT(KEqual,"=");
	
	THTTPHdrVal val;
	if (headers.GetField(fieldName, 0, val) != KErrNotFound)
	{
		RStringF cookieValueName = pool.StringF(HTTP::ECookieValue,RHTTPSession::GetTable());
		RStringF cookieNameName = pool.StringF(HTTP::ECookieName,RHTTPSession::GetTable());
		RStringF cookiePathName = pool.StringF(HTTP::EPath,RHTTPSession::GetTable());
	
		if (val.StrF() == pool.StringF(HTTP::ECookie, RHTTPSession::GetTable()))
		{
			THTTPHdrVal cookieValue;
			THTTPHdrVal cookieName;
			THTTPHdrVal cookiePath;
			
			TInt parts = headers.FieldPartsL(fieldName);
	
			Mem::Fill((void*)iCookies.Ptr(), 1024, 0);
			
			// Get all the cookies.
			for (TInt i = 0; i < parts; i++)
			{
				headers.GetParam(fieldName, cookieValueName, cookieValue, i);
				headers.GetParam(fieldName, cookieNameName, cookieName, i);
				headers.GetParam(fieldName, cookiePathName, cookiePath, i);
				
				if ( GetHdrVal( cookieName, pool) )
					iCookies.Append(KEqual);
					
				if ( GetHdrVal( cookieValue, pool) )
				{	
					iCookies.Append(KPathName);
					GetHdrVal( cookiePath, pool);
					iCookies.Append(KSeparator);
				}
			}
		}
	}
}
Example #10
0
void CHttpTestCase9::OpenTestSessionL()
	{
	// Literals used in the function
	_LIT8(KWapTestUrl,			"http://WapTestIP/perl/wrong_resource.txt");

	// Replace the host name in the URL
	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile);
	CleanupStack::PushL(newUrl8);
	TPtr8 newUrlPtr8 = newUrl8->Des();

	TUriParser8 testURI;
	testURI.Parse(newUrlPtr8);

	//open a Session
	iSession.OpenL();
	iEngine->Utils().LogIt(_L("Session Created(9) (Default parameters"));
	//Get the iSession'string pool handle;
	iMyStrP = iSession.StringPool();
	//open string this testcase needs
	RStringF textPlain = iMyStrP.StringF(HTTP::ETextPlain, RHTTPSession::GetTable());
	RStringF textHtml = iMyStrP.StringF(HTTP::ETextHtml, RHTTPSession::GetTable());
	RStringF mimeType = iMyStrP.StringF(HTTP::EApplicationXWwwFormUrlEncoded, RHTTPSession::GetTable());

	//Create , open  in the CS a Transaction in iSession 
	iTransaction = iSession.OpenTransactionL(testURI, *this, iMyStrP.StringF(HTTP::EPOST,RHTTPSession::GetTable()));
	iEngine->Utils().LogIt(_L("Transaction Created in Session"));
	//Get a handle of the request in iTransaction
	RHTTPRequest myRequest = iTransaction.Request();
	RHTTPHeaders myHeaders = myRequest.GetHeaderCollection();
	//provide  some headers 
	THTTPHdrVal v2(textPlain);
	THTTPHdrVal v3(textHtml);
	THTTPHdrVal v4(6);
	THTTPHdrVal v5(mimeType);

	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()),v2);
	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()),v3);
	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentLength, RHTTPSession::GetTable()),v4);
	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentType, RHTTPSession::GetTable()), v5);

	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
	iEngine->Utils().LogIt(_L("Method:Post"));
	iEngine->Utils().LogIt(_L("Accept:test/plain,text/html"));
	iEngine->Utils().LogIt(_L("Content-Type: application/x-www-form-urlencoded"));
	iEngine->Utils().LogIt(_L("Content-Length: 6"));
	myRequest.SetBody(*this);
	CleanupStack::PopAndDestroy(newUrl8);
	}
Example #11
0
/**
Sets the headers.
@internalTechnology
@test
@param		aHeaders 	Headers collection
@param		aHdrField 	Header field to be added
@return		aHdrValue	Header value to be added	
*/
void CTestHttpBaseStep::SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue)
	{
	RStringF valStr = iSess.StringPool().OpenFStringL(aHdrValue);
	THTTPHdrVal val(valStr);
	aHeaders.SetFieldL(iSess.StringPool().StringF(aHdrField,RHTTPSession::GetTable()), val);
	valStr.Close();
	}
Example #12
0
void CHttpClient::SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue)
{
    RStringF valStr = iConnectionManager->GetHTTPSession().StringPool().OpenFStringL(aHdrValue);
    THTTPHdrVal val(valStr);
    aHeaders.SetFieldL(iConnectionManager->GetHTTPSession().StringPool().StringF(aHdrField,RHTTPSession::GetTable()), val);
    valStr.Close();
}
void CHeaderDecode::ProcessHeadersL(RHTTPTransaction aTrans)
	{
	RStringPool stringPool = aTrans.Session().StringPool();
	RHTTPHeaders headers = aTrans.Response().GetHeaderCollection();
	THTTPHdrVal hdrVal;

	//Check Content-Length header parameter is stored correctly
	RStringF contentLengthStr = stringPool.StringF(HTTP::EContentLength, aTrans.Session().GetTable());
	User::LeaveIfError(headers.GetField(contentLengthStr,0,hdrVal));

	if(headers.FieldPartsL(contentLengthStr) != 1)
		User::Leave(KErrArgument);

	if (hdrVal.Int() != 6)
		User::Leave(KErrArgument);
	}
/**
	This function is called to initiate the tests.
	It may leave with one of the system-wide error codes.
*/
void CTextModeTestPostBodyChunks::DoRunL()
	{
	// Open the HTTP session
	iSession.OpenL();
	CleanupClosePushL(iSession);
	RStringPool strP = iSession.StringPool();

	// Open a POST transactions, specifying this object as the request body 
	// data supplier
	TUriParser8 up;

	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KHttpPostBodyChunksUrl(), iIniSettingsFile);
	CleanupStack::PushL(newUrl8);
	TPtr8 newUrlPtr8 = newUrl8->Des();

	up.Parse(newUrlPtr8);
	
	iTransaction = iSession.OpenTransactionL(up, *this, strP.StringF(HTTP::EPOST,RHTTPSession::GetTable()));
	RHTTPRequest rq = iTransaction.Request();
	rq.SetBody(*this);
	RHTTPHeaders hdr = rq.GetHeaderCollection();
	THTTPHdrVal length(OverallDataSize());
	hdr.SetFieldL(strP.StringF(HTTP::EContentLength,RHTTPSession::GetTable()), length);
	THTTPHdrVal contType(strP.StringF(HTTP::EApplicationXWwwFormUrlEncoded, RHTTPSession::GetTable()));
	hdr.SetFieldL(strP.StringF(HTTP::EContentType, RHTTPSession::GetTable()), contType);
	
	// Create the delayed notifier
	iReleaseTimer = CDelayedBodyDataNotifier::NewL(iTransaction);
	CleanupStack::PushL(iReleaseTimer);
	CActiveScheduler::Add(iReleaseTimer);

	// Submit the transaction
	iTransaction.SubmitL();
	iFailureError = KErrNone;
	CActiveScheduler::Start();

	// Get the completion code and inform the engine.  Anything other than 
	// HTTP/200 status is a failure for this test.
	iEngine->SetCurrentStatusCode(iTransaction.Response().StatusCode());
	iExpectedStatusCode = 200;

	// Close anything opened
	CleanupStack::PopAndDestroy(3, &iSession); // and iReleaseTimer, newUrl8;

	// Check for failure error codes caught in MHFRunL
	User::LeaveIfError(iFailureError);
	}
void CHttpController::SetHeaderL( RHTTPHeaders& aHeaders, TInt aHdrField, const TDesC8& aHdrValue )
	{
	RStringF valStr = iSession.StringPool().OpenFStringL( aHdrValue );
	CleanupClosePushL( valStr );
	THTTPHdrVal val( valStr );
	aHeaders.SetFieldL( iSession.StringPool().StringF( aHdrField, RHTTPSession::GetTable() ), val );
	CleanupStack::PopAndDestroy( &valStr );
	}
void UPPayHttpConnection::AddHeaderL(RHTTPHeaders aHeaders, TInt aHeaderField, const TDesC8& aHeaderValue)
{
	RStringPool stringPool = iSession.StringPool();
	RStringF valStr = stringPool.OpenFStringL(aHeaderValue);
	THTTPHdrVal headerVal(valStr);
	aHeaders.SetFieldL(stringPool.StringF(aHeaderField, RHTTPSession::GetTable()), headerVal);
	valStr.Close();
}
void CHttpClientFilter::AddSessionHeadersL(RHTTPHeaders aTransactionHeaders, RHTTPHeaders aSessionHeaders)
	{
	THTTPHdrFieldIter iter = aSessionHeaders.Fields();

	while( !iter.AtEnd() )
		{
		RStringTokenF headerToken = iter();
		RStringF headerName = iStringPool.StringF(headerToken);

		// See if transaction headers already contains this header.
		TPtrC8 rawData;
		if( aTransactionHeaders.GetRawField(headerName, rawData) == KErrNotFound )
			{
			aSessionHeaders.GetRawFieldL(headerName,rawData);
			aTransactionHeaders.SetRawFieldL(headerName, rawData, KFieldSeparator);
			}
		++iter;
		}
	}
void CHttpController::SetHeaderL( RHTTPHeaders& aHeaders, const TDesC8& aHdrName,
		const TDesC8& aHdrValue )
	{
	RStringF nameStr = iSession.StringPool().OpenFStringL( aHdrName );
	CleanupClosePushL( nameStr );
	RStringF valStr = iSession.StringPool().OpenFStringL( aHdrValue );
	CleanupClosePushL( valStr );
	THTTPHdrVal val( valStr );
	aHeaders.SetFieldL( nameStr, val );
	CleanupStack::PopAndDestroy( 2, &nameStr );
	}
Example #19
0
AMInt32 AMHttpGetOption(AMHttpRequest request, AMHttpOption option,
    AMUInt8* outBuf, AMUInt32 inOutBufLen)
	{
	REINTERPRET( HttpConnectionInternal*, temp, request );
	RHTTPHeaders hdr = temp->Transaction->Request().GetHeaderCollection();
	
	TPtr8 ptr( outBuf, inOutBufLen );
	
	switch( option )
		{
		case AM_HTTP_TIMEOUT:
			{
			THTTPHdrVal val;
			hdr.GetField(temp->session->StringPool().StringF(HTTP::EWspProxyConnectionTimeout,
			    RHTTPSession::GetTable()), 0, val);
			ptr.Append( val.StrF().DesC() );
			break;
			}
		}
	}
TBool CTestTransaction::AddAcceptHeaderL(RHTTPHeaders &aHeaders, RStringPool &aStrPool)
	{
	//	some tests may require specific 'Accept' parameters
	TBuf8<KMaxAcceptLengthSize> acceptBuf;
	acceptBuf.Copy(Machine()->GetDefine(KITHAccept));
	RStringF accept = (acceptBuf.Length() == 0) ?
		aStrPool.StringF(HTTP::EAnyAny, RHTTPSession::GetTable()) : aStrPool.OpenFStringL(acceptBuf);
	THTTPHdrVal acceptHdr(accept);
	aHeaders.SetFieldL(aStrPool.StringF(HTTP::EAccept, RHTTPSession::GetTable()), acceptHdr);
	accept.Close();
	return ETrue;
	}
void CRefTestAgentManager::PrepareHTTPRequestHeadersL(RStringPool& aStringPool, RHTTPHeaders& aRequestHeaders) const
	{
	// Add the accept header for the reference test agent
	TBuf8 <KMaxDataTypeLength> mimeType;

	// Add accept header for Content only files
	mimeType.Copy(KRtaMimeContent());
	RStringF valStr = aStringPool.OpenFStringL(mimeType);
	CleanupClosePushL(valStr);
	THTTPHdrVal val1(valStr);
	aRequestHeaders.SetFieldL(aStringPool.StringF(HTTP::EAccept, RHTTPSession::GetTable()), val1);
	CleanupStack::PopAndDestroy(&valStr);
	
	// Add accept header for content and rights files
	mimeType.Copy(KRtaMimeContentRights());
	valStr = aStringPool.OpenFStringL(mimeType);
	CleanupClosePushL(valStr);
	THTTPHdrVal val2(valStr);
	aRequestHeaders.SetFieldL(aStringPool.StringF(HTTP::EAccept, RHTTPSession::GetTable()), val2);
	CleanupStack::PopAndDestroy(&valStr);
	}
// ----------------------------------------------------------------------------
// CWmDrmDlaDefaultHttpManager::SetHeaderL
// ----------------------------------------------------------------------------
void CWmDrmDlaDefaultHttpManager::SetHeaderL(
    RHTTPHeaders& aHeaders,
    TInt aHdrField,
    const TDesC8& aHdrValue ) const
    {
    RStringPool pool = iHttpSession.StringPool();
    RStringF valStr = pool.OpenFStringL( aHdrValue );
    CleanupClosePushL( valStr );
    THTTPHdrVal val( valStr );
    aHeaders.SetFieldL( HTTP_STRING( aHdrField ), val );
    CleanupStack::PopAndDestroy( &valStr ); // Close
    }
TInt CHttpController::ContentLength( RHTTPHeaders aHeaderCollection, RHTTPSession& aSession )
	{
	RStringF contetnLength = aSession.StringPool().StringF( HTTP::EContentLength,
			RHTTPSession::GetTable() );
	THTTPHdrVal contetnLengthValue;
	TInt error( aHeaderCollection.GetField( contetnLength, 0, contetnLengthValue ) );
	if ( error == KErrNone )
		{
		return contetnLengthValue.Int();
		}
	return error;
	}
void CHttpClientFilter::EnsureContentTypePresentL(RHTTPTransaction aTransaction)
	{
	// From RFC 2616 Section 7.2.1 - 
	//
	// Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type
	// header field defining the media type of that body. If and only if the 
	// media type is not given by a Content-Type field, the recipient MAY attempt
	// to guess the media type via inspection of its content and/or the name 
	// extension(s) of the URI used to identify the resource. If the media type
	// remains unknown, the recipient SHOULD treat it as type "application/octet-stream".

	RHTTPHeaders headers = aTransaction.Response().GetHeaderCollection();
	THTTPHdrVal contentType;
	RStringF contentTypeString = iStringPool.StringF(HTTP::EContentType, iStringTable);
	if( headers.GetField(contentTypeString, 0, contentType) == KErrNotFound )
		{
		// There is no Content-Type header - add it with a value of 
		// "application/octet-stream".
		contentType.SetStrF(iStringPool.StringF(HTTP::EApplicationOctetStream, iStringTable));
		headers.SetFieldL(contentTypeString, contentType);
		}
	}
Example #25
0
RHTTPTransaction CTestCase15::GetTransactionL(TInt aIndex, RHTTPSession aSession, MHTTPTransactionCallback& aClient)
	{
	__ASSERT_ALWAYS(aIndex<KTransactionCount, User::Invariant());
	
	RStringF method = aSession.StringPool().StringF(HTTP::EGET,RHTTPSession::GetTable());
	_LIT8(KTxtUri, "http://127.0.0.1");
	TUriParser8 uri; 
	uri.Parse(KTxtUri());
	
	// Buffer size needs to be reduced in the session property before the first transaction.
	if( aIndex == 0 )
		{
		RHTTPConnectionInfo connInfo = aSession.ConnectionInfo();
		connInfo.SetPropertyL(aSession.StringPool().StringF(HTTP::EBatchingBufferSize,RHTTPSession::GetTable()), KBufferSize);
		}
		
	// If this is the 2nd request add large amount of header data to make the request
	// larger than the buffer size
	if( aIndex == 2 )
		{
		// Add a fairly large header
		RHTTPTransaction trans = aSession.OpenTransactionL(uri, aClient, method);
		RHTTPHeaders headers = trans.Request().GetHeaderCollection();
		
		_LIT8(KTxtHeaderName, "This_Is_A_Long_Header_Name");
		_LIT8(KTxtHeaderValue, "This_Is_A_Long_Header_Value_abcdefghijklmnopqrstuvwxyz1234567890");
		RStringF headerStrName = aSession.StringPool().OpenFStringL(KTxtHeaderName());
		CleanupClosePushL(headerStrName);
		RStringF headerStrValue = aSession.StringPool().OpenFStringL(KTxtHeaderValue());
		CleanupClosePushL(headerStrValue);
		THTTPHdrVal headerValue(headerStrValue);
		headers.SetFieldL(headerStrName, headerValue);
		CleanupStack::PopAndDestroy(2, &headerStrName);
		
		return trans;
		}
		
	return aSession.OpenTransactionL(uri, aClient, method);
	}
TBool CTestTransaction::SetContentLengthL(RHTTPHeaders &aHeaders, RStringPool &aStrPool)
	{
	TBuf8<KMaxContentLengthSize> contLengthBuf;
	contLengthBuf.Copy(Machine()->GetDefine(KITHContentLength));
	if (contLengthBuf.Length() != 0)
		{
		RStringF contLengthStr = aStrPool.OpenFStringL(contLengthBuf);
		THTTPHdrVal contLength(contLengthStr);
		aHeaders.SetFieldL(aStrPool.StringF(HTTP::EContentLength, RHTTPSession::GetTable()), contLength);
		contLengthStr.Close();
		}

	return ETrue;
	}
TBool CTestTransaction::AcceptEncodingL(RHTTPHeaders &aHeaders, RStringPool &aStrPool)
	{
	TBuf8<KMaxAcceptEncodingSize> acceptEncodingBuf;
	acceptEncodingBuf.Copy(Machine()->GetDefine(KITHAcceptEncoding));
	if (acceptEncodingBuf.Length() > 0)
		{
		RStringF acceptEncoding = aStrPool.OpenFStringL(acceptEncodingBuf);
		THTTPHdrVal acceptEncodingHdr(acceptEncoding);
		aHeaders.SetFieldL(aStrPool.StringF(HTTP::EAcceptCharset, RHTTPSession::GetTable()), acceptEncodingHdr);
		acceptEncoding.Close();
		}

	return ETrue;
	}
TBool CTestTransaction::SetUserAgentL(RHTTPHeaders &aHeaders, RStringPool &aStrPool)
	{
	//	get the DEFINE for UserAgent
	TBuf8<KMaxUserAgentSize> userAgentBuf;
	userAgentBuf.Copy(Machine()->GetDefine(KITHUserAgent));

	TInt iLen = userAgentBuf.Length();
	//	assign the selection
	RStringF agent = (iLen == 0) ? aStrPool.OpenFStringL(KUserAgent) : aStrPool.OpenFStringL(userAgentBuf);
	THTTPHdrVal userAgent(agent);
	aHeaders.SetFieldL(aStrPool.StringF(HTTP::EUserAgent, RHTTPSession::GetTable()), userAgent);
	agent.Close();

	return ETrue;
	}
// -----------------------------------------------------------------------------
// CHttpCacheManager::VSSRequestCheck
//
// -----------------------------------------------------------------------------
//
TBool CHttpCacheManager::VSSRequestCheckL( const RHTTPTransaction& aTrans,
                                           const RHTTPHeaders& aHttpHeader,
                                           const TDesC8& aUrl )
    {
    TBool VSSTransaction ( EFalse );
    if ( iVSSCacheEnabled && HttpCacheUtil::VSSCacheContent( aUrl, iVSSWhiteList ) )
        {
        RStringPool strP = aTrans.Session().StringPool();

#ifdef __CACHELOG__
        RHTTPHeaders headers ( aHttpHeader );
        HBufC8* responseHeaderStr8 = HttpCacheUtil::HeadersToBufferLC( headers, strP );
        HBufC* responseHeaderStr;
        if( responseHeaderStr8 )
            {
            responseHeaderStr = HBufC::NewL( responseHeaderStr8->Length() );
            responseHeaderStr->Des().Copy( responseHeaderStr8->Des() );
            CleanupStack::PopAndDestroy(); //  responseHeaderStr8;
            TPtrC headerStr( responseHeaderStr->Des() );
            HttpCacheUtil::WriteLog( 0, _L("========== VSS Header Start =========\n") );
            HttpCacheUtil::WriteLog( 0, responseHeaderStr->Des() );
            HttpCacheUtil::WriteLog( 0, _L("========== VSS Header End =========\n") );
            delete responseHeaderStr;
            }
#endif

        TPtrC8 nameStr ( KVSSHeaderFieldName() );

        RStringF VSSnameStr = strP.OpenFStringL( nameStr );
        CleanupClosePushL<RStringF>( VSSnameStr);

        THTTPHdrVal tempVal;
        if ( aHttpHeader.GetField( VSSnameStr, 0, tempVal ) == KErrNone )
            {
            TPtrC8 valueStr ( KVSSHeaderFieldValue() );
            RStringF VSSValueStr = strP.OpenFStringL( valueStr );
            CleanupClosePushL<RStringF>( VSSValueStr );

            if ( tempVal == VSSValueStr )
                {
                VSSTransaction      = ETrue;
                }
            CleanupStack::PopAndDestroy(); // VSSValueStr
            }
        CleanupStack::PopAndDestroy(); // VSSnameStr
        } //end if( iVSSCacheEnabled && HttpCacheUtil::VSSCacheContent( aUrl, iVSSWhiteList ) )
    return VSSTransaction;
    }
TBool CTestTransaction::AddRequestBodyL( RHTTPHeaders &aHeaders,
									    RStringPool &aStrPool)
	{
	//	the content type info will be in $ContentType$. If NULL or Empty then an error generated
	TBuf8<KMaxContentTypeSize> contTypeBuf;
	contTypeBuf.Copy(Machine()->GetDefine(KITHContentType));
	if (contTypeBuf.Length() == 0)
		return EFalse; //Error(KErrArgument, THA_KErrNoContentTypeDefined, &transmthd);

	RStringF contTypeStr = aStrPool.OpenFStringL(contTypeBuf);
	THTTPHdrVal contType(contTypeStr);
	aHeaders.SetFieldL(aStrPool.StringF(HTTP::EContentType, RHTTPSession::GetTable()), contType);
	contTypeStr.Close();

	MHTTPDataSupplier *dataSupplier = this;
	
    iTransaction.Request().SetBody(*dataSupplier);

	return ETrue;
	}