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); } } } } }
AMInt32 AMHttpGetResponseInfo(AMHttpResponse response, AMHttpQueryCode code, AMUInt8* outBuf, AMUInt32 inOutBufLen) { REINTERPRET( HttpConnectionInternal*, temp, response ); RHTTPResponse resp = temp->Transaction->Response(); RHTTPHeaders headers = resp.GetHeaderCollection(); TPtr8 ptr( outBuf, inOutBufLen ); switch( code ) { case AM_HTTP_STATUS_CODE: { ptr.AppendNum( resp.StatusCode() ); break; } case AM_HTTP_VERSION: { ptr.Append( resp.Version().Name() ); break; } } }
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; } }
// ---------------------------------------------------------------------------- // CWmDrmDlaDefaultHttpManager::MHFRunL // ---------------------------------------------------------------------------- void CWmDrmDlaDefaultHttpManager::MHFRunL( RHTTPTransaction aTransaction, const THTTPEvent& aEvent ) { LOGFN( "CWmDrmDlaDefaultHttpManager::MHFRunL" ); RHTTPResponse response; TPtrC8 dataChunk; // Either ESucceeded or EFailed will eventually occur switch ( aEvent.iStatus ) { case THTTPEvent::EGotResponseHeaders: response = aTransaction.Response(); iInCallback = ETrue; iObserver.OnResponseHeadersL( response, response.GetHeaderCollection(), iHttpSession.StringPool(), response.StatusCode() ); break; case THTTPEvent::EGotResponseBodyData: // A member variable is used to store the body to avoid two // potential problems: // - OnResponseBodyDataL leaves // - Stop is called from within OnResponseBodyDataL iBody = aTransaction.Response().Body(); User::LeaveIfNull( iBody ); iBody->GetNextDataPart( dataChunk ); iInCallback = ETrue; iObserver.OnResponseBodyDataL( dataChunk ); // Verify that iBody wasn't already released // for example by calling Stop within ResponseBodyDataL if ( iBody ) { iBody->ReleaseData(); iBody = NULL; } break; case THTTPEvent::ESucceeded: case THTTPEvent::EFailed: // Deal with both the same as iError will either be negative or // KErrNone // If the user cancelled the credentials dialog then make sure we // return KErrCancel HandleDownloadComplete( iCredentialsOk ? iError : KErrCancel ); break; default: // This will capture system and HTTP lib errors // For positive codes iError will remain to KErrNone if ( aEvent.iStatus < KErrNone ) { iError = aEvent.iStatus; } break; } iInCallback = EFalse; }
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); } } }
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 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; } }