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)); } } }
void CTestCase2::AddConnectionCloseHeaderL(RHTTPTransaction aTransaction) { RStringF name = aTransaction.Session().StringPool().StringF(HTTP::EConnection, RHTTPSession::GetTable()); THTTPHdrVal value = aTransaction.Session().StringPool().StringF(HTTP::EClose, RHTTPSession::GetTable()); aTransaction.Request().GetHeaderCollection().SetFieldL(name, value); }
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::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); } } }
EXPORT_C void CExampleCookieManager::GetCookiesL(RHTTPTransaction aTransaction, RArray<CCookie*>& aCookieList, TBool& aCookie2Reqd) { // For comparing cookies to insert them in the correct order to the returned array TLinearOrder<CCookie*> compareFunc(CompareCookiePaths); // Ensure the array is empty __ASSERT_DEBUG(aCookieList.Count()==0, HTTPCookiePanic::Panic(HTTPCookiePanic::EGetCookiesArrayNotEmpty)); const TInt numCookies = iCookies.Count(); for (TInt ii=0; ii<numCookies; ++ii) { CCookie* cookie = iCookies[ii]; const TUriC8& uri = aTransaction.Request().URI(); if(CheckDomainMatch(*cookie, uri) && CheckPathMatch(*cookie, uri) && CheckPortMatch(*cookie, uri) && CheckSecureMatch(*cookie, uri)) { User::LeaveIfError(aCookieList.InsertInOrderAllowRepeats(cookie, compareFunc)); if(!cookie->FromCookie2()) aCookie2Reqd = ETrue; } } }
void CHttpClientFilter::AlterRequestHeadersL(RHTTPTransaction aTransaction) { AddSessionHeadersL(aTransaction.Request().GetHeaderCollection(), iSession.RequestSessionHeadersL()); EnsurePathExistsL(aTransaction); EnsureContentLengthL(aTransaction); EnsureNoEndToEndHeadersInConnectionHeaderL(aTransaction); //removed the following Expect100 line to fix INC45389 & INC42505 - please do not add back in without checking these defects // AddExpect100ContinueL(aTransaction); }
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); }
// ----------------------------------------------------------------------------- // LocalHostCheckL // If the host is a local host, then remove the proxy property. Returns ETrue // if the transaction request URI was for a localhost. // ----------------------------------------------------------------------------- // TBool LocalHostCheckL(RHTTPTransaction& aTransaction, RStringPool& aStringPool) { _LIT8(KLoopbackIPv4Url, "http://127.0.0.1"); RHTTPRequest request = aTransaction.Request(); TUriC8 uri = request.URI(); TUriParser8 parserLoopBack; parserLoopBack.Parse(KLoopbackIPv4Url()); TInt match = parserLoopBack.Compare(uri, EUriHost); if (KErrNone != match) { _LIT8(KLocalHostUrl, "http://localhost"); // try another compare - compare against the "localhost". TUriParser8 parserLocalHost; parserLocalHost.Parse(KLocalHostUrl()); match = parserLocalHost.Compare(uri, EUriHost); if (KErrNone == match) { _LIT8(KLoopbackIPv4, "127.0.0.1"); // "localhost" resolves to "::1", manually, replace with "127.0.0.1" CUri8* newUri = CUri8::NewLC(uri); newUri->SetComponentL(KLoopbackIPv4(), EUriHost); request.SetURIL(newUri->Uri()); CleanupStack::PopAndDestroy(newUri); } } if (KErrNone == match) { // request is for localhost, explicitly state that this transaction // must not be sent to proxy. RStringF proxyUsageStrF = aStringPool.StringF(HTTP::EProxyUsage, RHTTPSession::GetTable()); RStringF dontUseProxyStrF = aStringPool.StringF(HTTP::EDoNotUseProxy, RHTTPSession::GetTable()); aTransaction.PropertySet().RemoveProperty(proxyUsageStrF); aTransaction.PropertySet().SetPropertyL(proxyUsageStrF, dontUseProxyStrF); //RStringF proxyAddrStrF = aStringPool.StringF(HTTP::EProxyAddress, // RHTTPSession::GetTable()); //aTransaction.PropertySet().RemoveProperty(proxyAddrStrF); return ETrue; } return EFalse; }
// ----------------------------------------------------------------------------- // CHttpCacheManager::RequestL // // ----------------------------------------------------------------------------- // EXPORT_C TInt CHttpCacheManager::RequestL( RHTTPTransaction& aTrans, TBrCtlDefs::TBrCtlCacheMode aCacheMode, THttpCacheEntry& aCacheEntry ) { // TInt status( KErrNotFound ); if( iCacheEnabled || iVSSCacheEnabled ) { CHttpCacheHandler* cache = CacheHandler( aTrans.Request().URI().UriDes(), NULL ) ; // adjust cache mode in case of offline operation if( iOfflineMode ) { aCacheMode = TBrCtlDefs::ECacheModeOnlyCache; } // if( cache ) { status = cache->RequestL( aTrans, aCacheMode, aCacheEntry ); // save cache handler even if the entry is not in the cache // so that when the response comes back, we do not need to // check the url if( status == KErrNotFound && iVSSCacheEnabled ) { status = iphoneSpecificCache->RequestL( aTrans, aCacheMode, aCacheEntry ); if( (status == KErrNotReady) || (status == KErrNone ) ) { aCacheEntry.iCacheHandler = iphoneSpecificCache; } else { // No entry found in any cache. Default to normal cache aCacheEntry.iCacheHandler = cache; } } else { aCacheEntry.iCacheHandler = cache; } } //end if( cache ) }//end if( iCacheEnabled || iVSSCacheEnabled ) return status; }
// ----------------------------------------------------------------------------- // CHttpCacheManager::ReceivedResponseHeadersL // // ----------------------------------------------------------------------------- // EXPORT_C void CHttpCacheManager::ReceivedResponseHeadersL( RHTTPTransaction& aTrans, THttpCacheEntry& aCacheEntry ) { if ( iCacheEnabled || iVSSCacheEnabled ) { if ( iVSSCacheEnabled && VSSRequestCheckL( aTrans, aTrans.Response().GetHeaderCollection(), aTrans.Request().URI().UriDes() ) ) { //Modify the cache handler if VSS specific aCacheEntry.iCacheHandler = iphoneSpecificCache; } if ( aCacheEntry.iCacheHandler ) { aCacheEntry.iCacheHandler->ReceivedResponseHeadersL( aTrans, aCacheEntry ); } } }
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); }
void CHttpClientFilter::EnsurePathExistsL(RHTTPTransaction aTransaction) { RHTTPRequest request = aTransaction.Request(); TUriC8 originalUri = request.URI(); // There is alwaya a path in a uri - ensure that it is not empty. const TDesC8& path = originalUri.Extract(EUriPath); TBool pathPresent = (path.Length() > 0); TBool hostPresent = originalUri.IsPresent(EUriHost); // If there is no path then make sure the uri // ends in '/' - server root path. if( hostPresent && !pathPresent ) { _LIT8(KDefaultUriPath, "/"); CUri8* uri = CUri8::NewLC(originalUri); uri->SetComponentL(KDefaultUriPath, EUriPath); request.SetURIL(uri->Uri()); CleanupStack::PopAndDestroy(uri); } }
// ----------------------------------------------------------------------------- // LocalHostCheckL // If the host is a local host. Returns ETrue // if the transaction request URI was for a localhost. // ----------------------------------------------------------------------------- // TBool LocalHostCheckL(RHTTPTransaction& aTransaction) { _LIT8(KLoopbackIPv4Url, "http://127.0.0.1"); RHTTPRequest request = aTransaction.Request(); TUriC8 uri = request.URI(); TUriParser8 parserLoopBack; parserLoopBack.Parse(KLoopbackIPv4Url()); TInt match = parserLoopBack.Compare(uri, EUriHost); if (KErrNone != match) { _LIT8(KLocalHostUrl, "http://localhost"); // try another compare - compare against the "localhost". TUriParser8 parserLocalHost; parserLocalHost.Parse(KLocalHostUrl()); match = parserLocalHost.Compare(uri, EUriHost); if (KErrNone == match) { _LIT8(KLoopbackIPv4, "127.0.0.1"); // "localhost" resolves to "::1", manually, replace with "127.0.0.1" CUri8* newUri = CUri8::NewLC(uri); newUri->SetComponentL(KLoopbackIPv4(), EUriHost); request.SetURIL(newUri->Uri()); CleanupStack::PopAndDestroy(newUri); } } if (KErrNone == match) { return ETrue; } return EFalse; }
void CTestFilter::EncodeBasicAuthL(RString& aUsername, RString& aPW, RHTTPTransaction& aTransaction) { // Standard, plain-text HTTP - Base 64 the name and password TBase64 codec; HBufC8* nameAndPW = HBufC8::NewMaxLC(aUsername.DesC().Length() + aPW.DesC().Length() + 1); _LIT8(KBasicAuthFormatString, "%S:%S"); nameAndPW->Des().Format(KBasicAuthFormatString, &aUsername.DesC(), &aPW.DesC()); // Conservatively allocate a buffer twice as big as the unencoded // buffer for the encoded string. HBufC8* encoded = HBufC8::NewMaxLC(nameAndPW->Des().Length() * 2); TPtr8 encodedPtr(encoded->Des()); codec.Encode(*nameAndPW, encodedPtr); RString encodedString = iStringPool.OpenStringL(*encoded); CleanupStack::PopAndDestroy(2, nameAndPW); CleanupClosePushL(encodedString); RHTTPHeaders requestHeaders(aTransaction.Request().GetHeaderCollection()); requestHeaders.RemoveField(iStringPool.StringF(HTTP::EAuthorization,RHTTPSession::GetTable())); requestHeaders.SetFieldL(iStringPool.StringF(HTTP::EAuthorization,RHTTPSession::GetTable()), THTTPHdrVal(iStringPool.StringF(HTTP::EBasic,RHTTPSession::GetTable()))); requestHeaders.SetFieldL(iStringPool.StringF(HTTP::EAuthorization,RHTTPSession::GetTable()), THTTPHdrVal(encodedString)); aTransaction.PropertySet().SetPropertyL(iStringPool.StringF(HTTP::EAuthorization,RHTTPSession::GetTable()), THTTPHdrVal(encodedString)); CleanupStack::PopAndDestroy(&encodedString); }
// --------------------------------------------------------- // CTransactionObserver::MHFRunL // --------------------------------------------------------- // void CTransactionObserver::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) { switch( aEvent.iStatus ) { case THTTPEvent::EGotResponseBodyData: { MHTTPDataSupplier* respBody = aTransaction.Response().Body(); TPtrC8 buf; respBody->GetNextDataPart( buf ); iDownload->SetStringAttribute( EDlAttrContinueBody, buf ); respBody->ReleaseData(); } break; case THTTPEvent::ESucceeded: { iDownload->SetIntAttribute( EDlAttrSucceeded, 0 ); } break; case THTTPEvent::EFailed: case THTTPEvent::EMoreDataReceivedThanExpected: case THTTPEvent::EUnrecoverableError: case THTTPEvent::ETooMuchRequestData: { iDownload->SetIntAttribute( EDlAttrFailed, aEvent.iStatus ); } break; case THTTPEvent::ERedirectedPermanently: { iDownload->SetStringAttribute( EDlAttrRedirectedPermanently, aTransaction.Request().URI().UriDes() ); } break; case THTTPEvent::ERedirectedTemporarily: { iDownload->SetStringAttribute( EDlAttrRedirectedTemporary, aTransaction.Request().URI().UriDes() ); } break; default: { if ( aEvent.iStatus == KErrHttpPartialResponseReceived ) { //Partial response has been received and connection has been disconnected. This error will be //propagated to the client only, if the HTTP:ENotifyOnDisconnect property is set with a value //HTTP::EEnableDisconnectNotification //This error code was cancelling the pausable download. This error shud be ignored to keep the //paused download. //TSW Err ID : SXUU-77SRWL } else if( aEvent.iStatus < 0 ) // error occured -> leave will be handled in OnError() { iDownload->SetIntAttribute( EDlAttrFailed, aEvent.iStatus ); } } break; } }
void CHttpTestCase4::DoRunL() { // Literals used in the function _LIT8(KWapTestUrl, "http://WapTestIP/perl/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(TC4)")); iEngine->Utils().LogIt(_L("Session parameters: Default")); //Get the mySession'string pool handle; iMyStrP = mySession.StringPool(); //get strings 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()); //Open a Transaction in mySession RHTTPTransaction myTransaction; myTransaction = mySession.OpenTransactionL(testURI, *this, iMyStrP.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(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); myTransaction.SubmitL(); CActiveScheduler::Start(); //close Transaction and session 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); }