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 #2
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);
				}
			}
		}
	}
}
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);
	}
Example #4
0
void CHttpHdrTest::TestHeaderCollL()
	{
	// Open strings needed in this test

	RStringF userAgentStr = iStrP.StringF(HTTP::EUserAgent,RHTTPSession::GetTable());
	RStringF textPlainStr = iStrP.StringF(HTTP::ETextPlain,RHTTPSession::GetTable());
	RStringF qStr = iStrP.StringF(HTTP::EQ,RHTTPSession::GetTable());
	RStringF accStr = iStrP.StringF(HTTP::EAccept,RHTTPSession::GetTable());
	RStringF textHtmlStr = 	iStrP.StringF(HTTP::ETextHtml,RHTTPSession::GetTable());
	RStringF wmlStr = 	iStrP.StringF(HTTP::ETextVndWapWml,RHTTPSession::GetTable());
	RStringF symbGTWapStr = iStrP.OpenFStringL(_L8("SymbGTWap"));
	CleanupClosePushL(symbGTWapStr);

	//

	CTextModeHeaderCodec* headerCodec = CTextModeHeaderCodec::NewL(iStrP);
	CleanupStack::PushL(headerCodec);
	CHeaders* headers =  CHeaders::NewL(*headerCodec);
	CleanupStack::PushL(headers);
	RHTTPHeaders hdr = headers->Handle();
	
	THTTPHdrVal uaStr(symbGTWapStr);
	hdr.SetFieldL(userAgentStr, uaStr);

	THTTPHdrVal dummy;
	TestL(hdr.GetField(userAgentStr,0,dummy) == KErrNone);
	
	hdr.RemoveField(userAgentStr);

	TestL(hdr.GetField(userAgentStr,0,dummy) == KErrNotFound);

	THTTPHdrVal htmlStr(textHtmlStr);
	THTTPHdrVal q(THTTPHdrVal::TQConv(0.5));
	hdr.SetFieldL(accStr, htmlStr, qStr, q);
	
	THTTPHdrVal wml(wmlStr);
	THTTPHdrVal q2(THTTPHdrVal::TQConv(0.3));
	hdr.SetFieldL(accStr, wml, qStr, q2);

	THTTPHdrVal plainStr(textPlainStr);
	THTTPHdrVal q3(THTTPHdrVal::TQConv(0.1));
	hdr.SetFieldL(accStr, plainStr, qStr, q3);
	TestL(hdr.FieldPartsL(accStr) == 3);

	THTTPHdrVal v1;
	hdr.GetField(accStr,0,v1);
	TestL(v1.Type() == THTTPHdrVal::KStrFVal);
	TestL(v1.StrF().Index(RHTTPSession::GetTable()) == textHtmlStr.Index(RHTTPSession::GetTable()));
	THTTPHdrVal v2;
	TestL(!hdr.GetParam(accStr, qStr, v2));
	hdr.GetField(accStr, 1,v2);
	TestL(v1.Type() == THTTPHdrVal::KStrFVal);

	TestL(v2.StrF().Index(RHTTPSession::GetTable()) == wmlStr.Index(RHTTPSession::GetTable()));
	THTTPHdrVal v3;
	TestL(!hdr.GetParam(accStr, qStr, v3, 1));
	hdr.GetField(accStr, 2,v3);
	TestL(v3.Type() == THTTPHdrVal::KStrFVal);
	TestL(v3.StrF().Index(RHTTPSession::GetTable()) == textPlainStr.Index(RHTTPSession::GetTable()));
	TestL(!hdr.GetParam(accStr, qStr, v3, 2));

	CleanupStack::PopAndDestroy(3); 
	}