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; } }
TInt CTestMessageComposer::NextHeaderL(TPtrC8& aHeaderName, TPtrC8& aHeaderValue) { if(iFlag) { THTTPHdrFieldIter it = iHTTPHeaders.Fields(); iFlag = EFalse; while(!it.AtEnd()) { // Get field current field. RStringF name = iStringPool.StringF(it()); CleanupClosePushL(name); // Get the OTA version of the field value TPtrC8 value; iRequest.GetHeaderCollection().GetRawField(name, value); User::LeaveIfError(iHeaders.Append(THeaderField(name.DesC(), value))); // Move onto next header field... ++it; CleanupStack::PopAndDestroy(&name); } } TInt error = ( iHeaderIndex < iHeaders.Count() ) ? KErrNone : KErrNotFound; if( iHeaderIndex < iHeaders.Count() ) { // Give the current header info... THeaderField header = iHeaders[iHeaderIndex]; aHeaderName.Set(header.iName); aHeaderValue.Set(header.iValue); // Loop to next header... ++iHeaderIndex; } else { // No more headers - change state iState = EPendingHasBody; } return error; }
void CTestTransaction::DumpRespHeaders(RHTTPTransaction &aTrans) { RHTTPResponse resp = aTrans.Response(); RStringPool strP = aTrans.Session().StringPool(); RHTTPHeaders hdr = resp.GetHeaderCollection(); THTTPHdrFieldIter it = hdr.Fields(); TBuf<32> fieldName16; TBuf<128> fieldVal16; while (it.AtEnd() == EFalse) { RStringTokenF fieldNameTk = it(); RStringF fieldName = strP.StringF(fieldNameTk); THTTPHdrVal hVal; if (hdr.GetField(fieldName, 0, hVal) == KErrNone) { TPtrC8 fieldNameStr(strP.StringF(fieldName).DesC()); if (fieldNameStr.Length() > 32) fieldNameStr.Set(fieldNameStr.Left(32)); fieldName16.Copy(fieldNameStr); THTTPHdrVal fieldVal; hdr.GetField(fieldName, 0, fieldVal); switch (fieldVal.Type()) { case THTTPHdrVal::KTIntVal: Log(_L("%S: %d"), &fieldName16, fieldVal.Int()); break; case THTTPHdrVal::KStrVal: case THTTPHdrVal::KStrFVal: { TPtrC8 fieldValStr(strP.StringF(fieldVal.StrF()).DesC()); if (fieldValStr.Length() > 128) fieldValStr.Set(fieldValStr.Left(128)); fieldVal16.Copy(fieldValStr); Log(_L("%S: %S"), &fieldName16, &fieldVal16); // see if we've got the Content-Type header if (fieldName16.Find(KHTTPContentType) != KErrNotFound) { // check that the contenttype script sets matches (in some way) received header TBuf8<KMaxContentTypeSize> contTypeBuf; contTypeBuf.Copy(Machine()->GetDefine(KITHContentType)); TInt iPos = fieldValStr.Find(contTypeBuf); if (iPos == KErrNotFound) Log(_L(" - Content Type string [%S:%S] is different to ContentType setting"), &fieldName16, &fieldVal16); else Log(_L(" - Content Type [%S:%S] acknowledged"), &fieldName16, &fieldVal16); } } break; case THTTPHdrVal::KDateVal: { TDateTime myDate = fieldVal.DateTime(); WriteDateStamp(myDate); Log(_L(" : %S"), &fieldName16); } break; default: Log(_L("%S: <unrecognised value type>"), &fieldName16); break; } } ++it; } }
void UPPayHttpConnection::ParaseResponseHeaders(RHTTPResponse resp) { RHTTPHeaders headers = resp.GetHeaderCollection(); THTTPHdrVal aHeaderValue; iStatusCode = resp.StatusCode(); if (iStatusCode >= 200 && iStatusCode < 300) { RStringF contLength = stringPool.OpenFStringL(_L8("Content-Length")); headers.GetField(contLength, 0, aHeaderValue); contLength.Close(); if (aHeaderValue.Type() == THTTPHdrVal::KTIntVal) { iContentLength = aHeaderValue.Int(); } else { iContentLength = 200 * 1024; } // if(iContentStartPos != 0) // { // HBufC8* fieldValBuf = HBufC8::NewLC(KMaxHeaderValueLength); // RStringF contentrange= stringPool.OpenFStringL(_L8("Content-Range")); // TPtrC8 rawField(fieldValBuf->Des()); // if(headers.GetRawField(contentrange,rawField)==KErrNone) // { // fieldValBuf->Des().Zero(); // } // contentrange.Close ( ); // CleanupStack::PopAndDestroy(fieldValBuf); // } } // // else // { // Stop(); // iObserver.StateChange(EHttpError); // } if (response_header) { delete response_header; } response_header = HBufC8::NewL(2048); Mem::FillZ((void*) response_header->Ptr(), 2048); TPtr8 headPtr = response_header->Des(); TVersion ver = resp.Version(); headPtr.AppendFormat(_L8("HTTP/%d.%d %d "), ver.iMajor, ver.iMinor, iStatusCode); headPtr.Append(resp.StatusText().DesC()); headPtr.Append(add2); RHTTPHeaders hdr = resp.GetHeaderCollection(); THTTPHdrFieldIter it = hdr.Fields(); THTTPHdrVal fieldVal; HBufC8* fieldValBuf = HBufC8::NewLC(KMaxHeaderValueLength); while (it.AtEnd() == EFalse) { RStringTokenF fieldName = it(); RStringF fieldNameStr = stringPool.StringF(fieldName); TPtrC8 rawField(fieldValBuf->Des()); if (hdr.GetRawField(fieldNameStr, rawField) == KErrNone) { headPtr.Append(fieldNameStr.DesC()); headPtr.Append(add1); headPtr.Append(rawField); headPtr.Append(add2); fieldValBuf->Des().Zero(); } ++it; } CleanupStack::PopAndDestroy(fieldValBuf); if (iStatusCode == 301 || iStatusCode == 302) { if (iObserver) { iObserver->StateChange(ERedirect); } } }
void CHttpController::ParseHeadersL( RHTTPTransaction& aTransaction ) { const TInt KMaxNumericLen = 32; RStringPool stringPool = aTransaction.Session().StringPool(); RHTTPHeaders header = aTransaction.Response().GetHeaderCollection(); THTTPHdrFieldIter iterator = header.Fields(); HBufC8* fieldName8 = NULL; HBufC8* fieldVal8 = NULL; CHttpHeaders* headers = CHttpHeaders::NewLC(); while ( !iterator.AtEnd() ) { RStringTokenF fieldName = iterator(); RStringF fieldNameStr = stringPool.StringF( fieldName ); THTTPHdrVal fieldVal; if ( header.GetField( fieldNameStr, 0, fieldVal ) == KErrNone ) { fieldName8 = fieldNameStr.DesC().AllocLC(); switch ( fieldVal.Type() ) { case THTTPHdrVal::KTIntVal: { fieldVal8 = HBufC8::NewLC( KMaxNumericLen ); TPtr8 ptr( fieldVal8->Des() ); ptr.Num( fieldVal.Int() ); break; } case THTTPHdrVal::KStrFVal: { RStringF fieldValStr = stringPool.StringF( fieldVal.StrF() ); fieldVal8 = fieldValStr.DesC().AllocLC(); break; } case THTTPHdrVal::KStrVal: { RString fieldValStr = stringPool.String( fieldVal.Str() ); fieldVal8 = fieldValStr.DesC().AllocLC(); break; } case THTTPHdrVal::KDateVal: { _LIT(KDateFormat,"%D%M%Y%/0%1%/1%2%/2%3%/3 %:0%H%:1%T%:2%S.%C%:3"); TDateTime date = fieldVal.DateTime(); const TInt KMaxDateBuferLength = 100; TBuf< KMaxDateBuferLength > dateBuffer; TTime time( date ); time.FormatL( dateBuffer, KDateFormat ); fieldVal8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( dateBuffer ); CleanupDeletePushL( fieldVal8 ); break; } default: User::Leave( KErrNotSupported );//new field types will be added in future break; } if ( !fieldVal8 ) { CleanupStack::PopAndDestroy( fieldName8 ); } else { headers->AddL( *fieldName8, *fieldVal8 ); CleanupStack::PopAndDestroy( 2, fieldName8 ); } fieldVal8 = NULL; fieldName8 = NULL; } ++iterator; } iObserver->HeadersReceivedL( headers ); CleanupStack::Pop( headers ); }
EXPORT_C void CHttpTestTransBase::DumpRespHeaders(RHTTPTransaction& aTrans) //dump the message's headers { //dump the message's headers RHTTPResponse resp = aTrans.Response(); TInt status = resp.StatusCode(); if (!iEngine->IsSilent()) iEngine->Utils().LogIt(_L("Status code = %d\n"), status); RStringPool strP = aTrans.Session().StringPool(); RHTTPHeaders hdr = resp.GetHeaderCollection(); THTTPHdrFieldIter it = hdr.Fields(); TBuf<32> fieldName16; TBuf<128> fieldVal16; while (it.AtEnd() == EFalse) { RStringTokenF fieldNameTk = it(); RStringF fieldName = strP.StringF(fieldNameTk); THTTPHdrVal hVal; if (hdr.GetField(fieldName,0,hVal) == KErrNone) { TPtrC8 fieldNameStr(strP.StringF(fieldName).DesC()); if (fieldNameStr.Length() > 32) fieldNameStr.Set(fieldNameStr.Left(32)); fieldName16.Copy(fieldNameStr); THTTPHdrVal fieldVal; hdr.GetField(fieldName,0,fieldVal); switch (fieldVal.Type()) { case THTTPHdrVal::KTIntVal: { iEngine->Utils().LogIt(_L("%S: %d\n"), &fieldName16, fieldVal.Int()); } break; case THTTPHdrVal::KStrVal: case THTTPHdrVal::KStrFVal: { TPtrC8 fieldValStr(strP.StringF(fieldVal.StrF()).DesC()); if (fieldValStr.Length() > 128) fieldValStr.Set(fieldValStr.Left(128)); fieldVal16.Copy(fieldValStr); iEngine->Utils().LogIt(_L("%S: %S\n"), &fieldName16, &fieldVal16); } break; case THTTPHdrVal::KDateVal: { TDateTime date = fieldVal.DateTime(); TTime t(date); TBuf<128> dateTimeString; TRAPD(err,t.FormatL(dateTimeString,KDateFormat)); if (err == KErrNone) iEngine->Utils().LogIt(_L("%S: %S\n"), &fieldName16, &dateTimeString); } break; default: { iEngine->Utils().LogIt(_L("%S: <unrecognised value type>\n"), &fieldName16); } } } ++it; } }
void CHttpHdrTest::TestHeaderCollIterL() { RStringF field1Str = iStrP.OpenFStringL(_L8("hcfield1")); CleanupClosePushL(field1Str); RStringF value1Str = iStrP.OpenFStringL(_L8("hcvalue1")); CleanupClosePushL(value1Str); RStringF field2Str = iStrP.OpenFStringL(_L8("hcfield2")); CleanupClosePushL(field2Str); RStringF value2Str = iStrP.OpenFStringL(_L8("hcvalue2")); CleanupClosePushL(value2Str); RStringF field3Str = iStrP.OpenFStringL(_L8("hcfield3")); CleanupClosePushL(field3Str); RStringF value3Str = iStrP.OpenFStringL(_L8("hcvalue3")); CleanupClosePushL(value3Str); RStringF field4Str = iStrP.OpenFStringL(_L8("hcfield4")); CleanupClosePushL(field4Str); RStringF value4Str = iStrP.OpenFStringL(_L8("hcvalue4")); CleanupClosePushL(value4Str); // CTextModeHeaderCodec* headerCodec = CTextModeHeaderCodec::NewL(iStrP); CleanupStack::PushL(headerCodec); CHeaders* headers = CHeaders::NewL(*headerCodec); CleanupStack::PushL(headers); RHTTPHeaders hdr = headers->Handle(); THTTPHdrVal str1(value1Str); hdr.SetFieldL(field1Str, str1); THTTPHdrVal str2(value2Str); hdr.SetFieldL(field2Str, str2); THTTPHdrVal str3(value3Str); hdr.SetFieldL(field3Str, str3); THTTPHdrVal str4(value4Str); hdr.SetFieldL(field4Str, str4); THTTPHdrFieldIter it = hdr.Fields(); TInt count = 0; while (it.AtEnd() == EFalse) { RStringTokenF nextTk = it(); RStringF nextStr = iStrP.StringF(nextTk); THTTPHdrVal hVal; TestL(hdr.GetField(nextStr,0,hVal)==KErrNone); switch (count) { case 0: TestL(nextStr.Index(RHTTPSession::GetTable()) == field1Str.Index(RHTTPSession::GetTable())); break; case 1: TestL(nextStr.Index(RHTTPSession::GetTable()) == field2Str.Index(RHTTPSession::GetTable())); break; case 2: TestL(nextStr.Index(RHTTPSession::GetTable()) == field3Str.Index(RHTTPSession::GetTable())); break; case 3: TestL(nextStr.Index(RHTTPSession::GetTable()) == field4Str.Index(RHTTPSession::GetTable())); break; } ++it; ++count; } // Close strings used in this test CleanupStack::PopAndDestroy(10); }
void CHttpEventHandler::DumpRespHeadersL(RHTTPTransaction& aTrans) { RHTTPResponse resp = aTrans.Response(); RStringPool strP = aTrans.Session().StringPool(); RHTTPHeaders hdr = resp.GetHeaderCollection(); THTTPHdrFieldIter it = hdr.Fields(); TBuf<CHttpConstants::KMaxHeaderNameLen> fieldName16; TBuf<CHttpConstants::KMaxHeaderValueLen> fieldVal16; while (it.AtEnd() == EFalse) { RStringTokenF fieldName = it(); RStringF fieldNameStr = strP.StringF(fieldName); THTTPHdrVal fieldVal; if (hdr.GetField(fieldNameStr,0,fieldVal) == KErrNone) { const TDesC8& fieldNameDesC = fieldNameStr.DesC(); fieldName16.Copy(fieldNameDesC.Left(CHttpConstants::KMaxHeaderNameLen)); switch (fieldVal.Type()) { case THTTPHdrVal::KTIntVal: iTest->Console()->Printf(_L("%S: %d\n"), &fieldName16, fieldVal.Int()); break; case THTTPHdrVal::KStrFVal: { RStringF fieldValStr = strP.StringF(fieldVal.StrF()); const TDesC8& fieldValDesC = fieldValStr.DesC(); fieldVal16.Copy(fieldValDesC.Left(CHttpConstants::KMaxHeaderValueLen)); iTest->Console()->Printf(_L("%S: %S\n"), &fieldName16, &fieldVal16); } break; case THTTPHdrVal::KStrVal: { RString fieldValStr = strP.String(fieldVal.Str()); const TDesC8& fieldValDesC = fieldValStr.DesC(); fieldVal16.Copy(fieldValDesC.Left(CHttpConstants::KMaxHeaderValueLen)); iTest->Console()->Printf(_L("%S: %S\n"), &fieldName16, &fieldVal16); } break; case THTTPHdrVal::KDateVal: { TDateTime date = fieldVal.DateTime(); TBuf<40> dateTimeString; TTime t(date); t.FormatL(dateTimeString,CHttpConstants::KDateFormat); iTest->Console()->Printf(_L("%S: %S\n"), &fieldName16, &dateTimeString); } break; default: iTest->Console()->Printf(_L("%S: <unrecognised value type>\n"), &fieldName16); break; } // Display realm for WWW-Authenticate header RStringF wwwAuth = strP.StringF(HTTP::EWWWAuthenticate,RHTTPSession::GetTable()); if (fieldNameStr == wwwAuth) { // check the auth scheme is 'basic' RStringF basic = strP.StringF(HTTP::EBasic,RHTTPSession::GetTable()); RStringF realm = strP.StringF(HTTP::ERealm,RHTTPSession::GetTable()); THTTPHdrVal realmVal; if ((fieldVal.StrF() == basic) && (!hdr.GetParam(wwwAuth, realm, realmVal))) { RStringF realmValStr = strP.StringF(realmVal.StrF()); fieldVal16.Copy(realmValStr.DesC()); iTest->Console()->Printf(_L("Realm is: %S\n"), &fieldVal16); } } } ++it; } }
void CSTTrackerConnection::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) { switch (aEvent.iStatus) { case THTTPEvent::EGotResponseHeaders: { // HTTP response headers have been received. Use // aTransaction.Response() to get the response. However, it's not // necessary to do anything with the response when this event occurs. LWRITELN(iLog, _L("[Trackerconnection] Got HTTP headers")); // Get HTTP status code from header (e.g. 200) RHTTPResponse resp = aTransaction.Response(); TInt status = resp.StatusCode(); if (status != 200) // ERROR, hiba esetén mi legyen? 404-et lekezelni! { LWRITE(iLog, _L("[Trackerconnection] Error, status = ")); TBuf<20> numBuf; numBuf.Num(status); LWRITELN(iLog, numBuf); Cancel(); if (iObserver) iObserver->TrackerConnectionFailedL(); break; } // Get status text (e.g. "OK") HLWRITE(iLog, _L("[Trackerconnection] Status text = ")); TBuf<32> statusText; statusText.Copy(resp.StatusText().DesC()); HLWRITELN(iLog, statusText); #ifdef LOG_TO_FILE RHTTPHeaders headers = aTransaction.Response().GetHeaderCollection(); THTTPHdrFieldIter i = headers.Fields(); for (i.First(); !(i.AtEnd()); ++i) { RStringF header = iSession.StringPool().StringF(i()); if ((header.DesC() == _L8("Content-Type"))) { HLWRITE(iLog, header.DesC()); HLWRITE(iLog, _L(": ")); THTTPHdrVal val; headers.GetField(header, 0, val); RStringF value = val.StrF(); HLWRITELN(iLog, value.DesC()); } else HLWRITELN(iLog, header.DesC()); } #endif } break; case THTTPEvent::EGotResponseBodyData: { // Part (or all) of response's body data received. Use // aTransaction.Response().Body()->GetNextDataPart() to get the actual // body data. // Get the body data supplier MHTTPDataSupplier* body = aTransaction.Response().Body(); TPtrC8 dataChunk; // GetNextDataPart() returns ETrue, if the received part is the last // one. TBool isLast = body->GetNextDataPart(dataChunk); //iDownloadedSize += dataChunk.Size(); HLWRITELN(iLog, _L8("[TrackerConnection] HTTP response body chunk received: ")); HLWRITELN(iLog, dataChunk); if (iReceiveBuffer) { HBufC8* temp = HBufC8::NewL( iReceiveBuffer->Length() + dataChunk.Length()); TPtr8 tempPtr(temp->Des()); tempPtr.Copy(*iReceiveBuffer); tempPtr.Append(dataChunk); delete iReceiveBuffer; iReceiveBuffer = temp; } else iReceiveBuffer = dataChunk.AllocL(); // Always remember to release the body data. body->ReleaseData(); // NOTE: isLast may not be ETrue even if last data part received. // (e.g. multipart response without content length field) // Use EResponseComplete to reliably determine when body is completely // received. if (isLast) { #ifdef LOG_TO_FILE _LIT(KBodyReceived,"Body received"); HLWRITELN(iLog, KBodyReceived); #endif //CSTBencode* bencodedResponse = CSTBencode::ParseL(*iReceiveBuffer); //iLog->WriteLineL(*iReceiveBuffer); // //if (bencodedResponse) //{ // CleanupStack::PushL(bencodedResponse); // iTorrent.ProcessTrackerResponseL(bencodedResponse); // CleanupStack::PopAndDestroy(); // bencodedResponse //} } } break; case THTTPEvent::EResponseComplete: { // Indicates that header & body of response is completely received. // No further action here needed. //_LIT(KTransactionComplete, "Transaction Complete"); //iLog->WriteLineL(KTransactionComplete); //iResult = ESucceeded; } break; case THTTPEvent::ESucceeded: { LWRITELN(iLog, _L("[Trackerconnection] HTTP transaction succeded")); CSTBencode* bencodedResponse = CSTBencode::ParseL(*iReceiveBuffer); //iLog->WriteLineL(*iReceiveBuffer); if (bencodedResponse && iObserver) { CleanupStack::PushL(bencodedResponse); iObserver->TrackerResponseReceivedL(*bencodedResponse); CleanupStack::PopAndDestroy(); // bencodedResponse } iRunning = EFalse; if (iObserver) iObserver->TrackerConnectionSucceededL(); } break; case THTTPEvent::EFailed: { LWRITELN(iLog, _L("[Trackerconnection] HTTP transaction failed")); iRunning = EFalse; if (iObserver) iObserver->TrackerConnectionFailedL(); } break; default: // There are more events in THTTPEvent, but they are not usually // needed. However, event status smaller than zero should be handled // correctly since it's error. { TBuf<64> text; if (aEvent.iStatus < 0) { LWRITE(iLog, _L("[Trackerconnection] HTTP transaction failed, ")); _LIT(KErrorStr, "Error: %d"); text.Format(KErrorStr, aEvent.iStatus); LWRITELN(iLog, text); // Just close the transaction on errors aTransaction.Close(); iRunning = EFalse; if (iObserver) iObserver->TrackerConnectionFailedL(); } else { // Other events are not errors (e.g. permanent and temporary // redirections) _LIT(KUnrecognisedEvent, "[Trackerconnection] Unrecognised event: %d"); text.Format(KUnrecognisedEvent, aEvent.iStatus); LWRITELN(iLog, text); } } break; } }