applayerprotocols/httptransportfw/Test/T_HttpPipeliningTest/CHeaderDecode.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2003-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 "CHeaderDecode.h"
       
    17 #include "httptestutils.h"
       
    18 
       
    19 const TInt KTransactionCount = 1;
       
    20 const TInt KConnectionCount = 1;
       
    21 _LIT8(KTxtRawRequest, "GET / HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n");
       
    22 _LIT8(KTxtRawResponse, "HTTP/1.1 200 OK\r\nWWW-Authenticate: BASIC realm=\r\nContent-Length: 6\r\nContent-Length: 6\r\n\r\nhello!");
       
    23 
       
    24 CHeaderDecode* CHeaderDecode::NewL(CHTTPTestUtils& aTestUtils)
       
    25 	{
       
    26 	CHeaderDecode* self = new (ELeave) CHeaderDecode(aTestUtils);
       
    27 	CleanupStack::PushL(self);
       
    28 	self->ConstructL();
       
    29 	CleanupStack::Pop(self);
       
    30 	return self;
       
    31 	}
       
    32 
       
    33 CHeaderDecode::CHeaderDecode(CHTTPTestUtils& aTestUtils)
       
    34 : CPipeliningTestCase(), iTestUtils(aTestUtils)
       
    35 	{
       
    36 	}
       
    37 
       
    38 void CHeaderDecode::ConstructL()
       
    39 	{
       
    40 	}
       
    41 
       
    42 CHeaderDecode::~CHeaderDecode()
       
    43 	{
       
    44 	}
       
    45 
       
    46 const TDesC& CHeaderDecode::TestCaseName() const
       
    47 	{
       
    48 	_LIT(KTxtTitle, "Header Decode");
       
    49 	return KTxtTitle();
       
    50 	}
       
    51 
       
    52 TInt CHeaderDecode::TotalTransactionCount() const
       
    53 	{
       
    54 	return KTransactionCount;
       
    55 	}
       
    56 
       
    57 TInt CHeaderDecode::ConnectionCount() const
       
    58 	{
       
    59 	return KConnectionCount;
       
    60 	}
       
    61 	
       
    62 RHTTPTransaction CHeaderDecode::GetTransactionL(TInt aIndex, RHTTPSession aSession, MHTTPTransactionCallback& aClient)
       
    63 	{
       
    64 	__ASSERT_ALWAYS(aIndex<KTransactionCount, User::Invariant());
       
    65 	
       
    66 	RStringF method = aSession.StringPool().StringF(HTTP::EGET,RHTTPSession::GetTable());
       
    67 	_LIT8(KTxtUri, "http://127.0.0.1");
       
    68 	TUriParser8 uri; 
       
    69 	uri.Parse(KTxtUri());
       
    70 	return aSession.OpenTransactionL(uri, aClient, method);
       
    71 	}
       
    72 
       
    73 const TDesC8& CHeaderDecode::GetRawRequest(TInt aConnectionIndex, TInt aTransIndex)
       
    74 	{
       
    75 	__ASSERT_ALWAYS( (aTransIndex<KTransactionCount) && (aConnectionIndex < KConnectionCount), User::Invariant());
       
    76 	
       
    77 	return KTxtRawRequest();
       
    78 	}
       
    79 	
       
    80 const TDesC8& CHeaderDecode::GetRawResponse(TInt aConnectionIndex, TInt aTransIndex)
       
    81 	{
       
    82 	__ASSERT_ALWAYS( (aTransIndex<KTransactionCount) && (aConnectionIndex < KConnectionCount), User::Invariant());
       
    83 
       
    84 	return KTxtRawResponse();
       
    85 	}
       
    86 	
       
    87 void CHeaderDecode::ProcessHeadersL(RHTTPTransaction aTrans)
       
    88 	{
       
    89 	RStringPool stringPool = aTrans.Session().StringPool();
       
    90 	RHTTPHeaders headers = aTrans.Response().GetHeaderCollection();
       
    91 	THTTPHdrVal hdrVal;
       
    92 
       
    93 	//Check Content-Length header parameter is stored correctly
       
    94 	RStringF contentLengthStr = stringPool.StringF(HTTP::EContentLength, aTrans.Session().GetTable());
       
    95 	User::LeaveIfError(headers.GetField(contentLengthStr,0,hdrVal));
       
    96 
       
    97 	if(headers.FieldPartsL(contentLengthStr) != 1)
       
    98 		User::Leave(KErrArgument);
       
    99 
       
   100 	if (hdrVal.Int() != 6)
       
   101 		User::Leave(KErrArgument);
       
   102 	}